我遇到了通过ansible运行远程脚本的问题。我需要在become root (run sudo su -)
之后运行远程脚本。
ansible无法在YML中由become_method
扎根吗?这里是否有任何配置文件问题或playbook命令问题?
[root@automation ansible]# ansible-playbook YML/disk_scan.yml -i hosts
SSH password:
PLAY [test] ***********************************************************************************************************************************************************************************
TASK [copy] ***********************************************************************************************************************************************************************************
fatal: [test101.com]: FAILED! => {"msg": "Missing sudo password"}
- hosts: test
# serial: 5
become: yes
become_method: sudo
become_user: root
gather_facts: no
tasks:
- copy:
src: /etc/ansible/scripts/Raid_check.py
dest: /tmp/
- name: Run Raid Check
command: python /tmp/Raid_check.py
register: command_output
- debug: msg="{{ command_output.stdout }}"
[defaults]
inventory = /etc/ansible/hosts
host_key_checking = false
remote_tmp = $HOME/.ansible/tmp
pattern = *
forks = 10
poll_interval = 15
ask_pass=True
sudo_user = root
user = test
remote_user = test
transport = smart
#module_lang = C
gathering = smart
fact_caching = redis
#sudo_exe = sudo
timeout = 15
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
action_plugins = /usr/share/ansible_plugins/action_plugins
callback_plugins = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins = /usr/share/ansible_plugins/lookup_plugins
vars_plugins = /usr/share/ansible_plugins/vars_plugins
filter_plugins = /usr/share/ansible_plugins/filter_plugins
deprecation_warnings=False
fact_caching = memory
[paramiko_connection]
[ssh_connection]
[accelerate]
accelerate_port = 5099
accelerate_timeout = 30
accelerate_connect_timeout = 5.0
accelerate_daemon_timeout = 30
fatal: [test101.com]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 12726\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to test101.com closed.\r\n",
"module_stdout": "\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
答案 0 :(得分:0)
运行cli命令时,您需要添加成为密码。
尝试ansible-playbook YML/disk_scan.yml -i hosts -K
。请注意,-K
是提示输入超级用户密码的简写。