---
- name: Transfer and execute a script.
hosts: jumpbox
remote_user: pppruser
any_errors_fatal: true
gather_facts: no
become: true
become_method: su
become_user: splunk
become_flags: '-s /bin/sh'
tasks:
- name: Transfer the script
copy: src=test.sh dest=/home/splunk/ mode=0777
- name: Execute the script
command: sh /export/home/splunk/test.sh
[splunk@ansible playbooks]$ cat test.sh
#!/bin/bash
cat /etc/passwd > /tmp/test
在main.yml脚本上方,在playbook命令下方使用
$ansible-playbook /etc/ansible/playbooks/main.yml --extra-vars "host=jumpbox" --ask-become-pass
SUDO password:
PLAY [Transfer and execute a script.] **********************************************************************************
TASK [Transfer the script] *********************************************************************************************
fatal: [192.168.1.20]: FAILED! => {"msg": "Timeout (12s) waiting for privilege escalation prompt: "}
NO MORE HOSTS LEFT *****************************************************************************************************
to retry, use: --limit @/etc/ansible/playbooks/main.retry
PLAY RECAP *********************************************************************************************************
192.168.1.20 : ok=0 changed=0 unreachable=0 failed=1
失败,出现错误。我尝试了来自多个论坛的不同选项和不同建议。但是没有任何效果。在目标服务器(192.168.1.20)上,我有remote_user(pppruser)和服务帐户(splunk)。 pppruser具有sudo特权。这是pppruser帐户的sudo列表
$sudo -l
User pppruser may run the following commands on this host:
(root) /bin/su - splunk
$sudo su - splunk
任何人都可以建议我在哪里需要进行配置更改,以便以splunk用户身份运行我的剧本执行,而不会出现问题。
- name: Transfer and execute a script.
hosts: jumpbox
remote_user: pppruser
any_errors_fatal: true
gather_facts: no
become: true
become_user: splunk
tasks:
- name: Transfer the script
copy: src=test.sh dest=/home/splunk/ mode=0777
- name: Execute the script
command: sh /export/home/splunk/test.sh