---
- 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 具有 splunk 的 sudo 权限。这是 pppruser 帐户的 sudo 列表
$sudo -l
User pppruser may run the following commands on this host:
(root) /bin/su - splunk
$sudo su - splunk
任何人都可以建议我在哪里需要更改配置,以便以 splunk 用户身份运行我的剧本执行没有问题。