Ansible 剧本仅适用于 root 用户,当 运行 其他 sudo 用户时失败

Ansible playbook only working with root user and failing when running with other sudo user

我的测试环境中有一个工作手册,我的用户是 root 用户 itslef,没有任何问题。 当我将剧本移至临时环境时,我的登录用户帐户是 "admin",即 sudo 用户。但是我所有的剧本在这种环境下都失败了。

---

- name: Replace the silent-install-server_ file to each Application Servers
  hosts: localhost,CCM,RM
  vars: 
    jts_file: /etc/ansible/roles/IBM2/files/silent-install-server_JTS.xml
    ccm_file: /etc/ansible/roles/IBM2/files/silent-install-server_CCM.xml
    rm_file: /etc/ansible/roles/IBM2/files/silent-install-server_RM.xml
    dest_dir: /opt/CLM-Web-Installer-Linux-6.0.5/im/linux.gtk.x86_64
  tasks:
    - name: check the folder existance
      stat: path=/opt/CLM-Web-Installer-Linux-6.0.5/im/linux.gtk.x86_64
      register: folder_exist

    - name: JTS Server
      copy:
        src: "{{ jts_file }}"
        dest: "{{ dest_dir }}/"
        mode: 777
        backup: yes
      delegate_to: localhost
      when: folder_exist.stat.exists == True

    - name: CCM Server
      copy:
        src: "{{ ccm_file }}"
        dest: "{{ dest_dir }}/"
        mode: 777
        backup: yes
      delegate_to: 10.16.24.102`enter code here`
      when: folder_exist.stat.exists == True

    - name: RM Server
      copy:
        src: "{{ rm_file }}"
        dest: "{{ dest_dir }}/"
        mode: 777
        backup: yes
      delegate_to: 10.16.24.103
      when: folder_exist.stat.exists == True

低于错误。

PLAY [Replace the silent-install-server_ file to each Application Servers] **********************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************
ok: [localhost]
fatal: [10.16.24.102]: FAILED! => {"msg": "Timeout (12s) waiting for privilege escalation prompt: "}
fatal: [10.165.240.103]: FAILED! => {"msg": "Timeout (12s) waiting for privilege escalation prompt: "}

TASK [check the folder existance] ***************************************************************************************************************************
ok: [localhost]

TASK [JTS Server] *******************************************************************************************************************************************
ok: [localhost -> localhost]

TASK [CCM Server] *******************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "Failed to get information on remote file (/opt/CLM-Web-Installer-Linux-6.0.5/im/linux.gtk.x86_64/silent-install-server_CCM.xml): Shared connection to 10.16.24.102 closed.\r\n"}
        to retry, use: --limit @/etc/ansible/roles/IBM2/tasks/best/silentiInstallerfile.retry

PLAY RECAP **************************************************************************************************************************************************
10.16.24.102             : ok=0    changed=0    unreachable=0    failed=1
10.16.24.103             : ok=0    changed=0    unreachable=0    failed=1
localhost                  : ok=3    changed=0    unreachable=0    failed=1

我的主机文件如下

[IHS]
10.16.24.100
[JTS]
10.16.24.101
[CCM]
10.16.24.102
[RM]
10.16.24.103

确保 admin@10.16.24.102 和 admin@10.165.240.103 能够“sudo su”。

fatal: [10.16.24.102]: FAILED! => {"msg": "Timeout (12s) waiting for privilege escalation prompt: "}

fatal: [10.165.240.103]: FAILED! => {"msg": "Timeout (12s) waiting for privilege escalation prompt: "}

如果你不是运行 root,你需要告诉ansible成为root

成为:是

这可以在每次游戏、清单中的每个主机或单个任务中完成

我建议为 admin@10.16.24.102 和 admin@10.165.240.103 设置无密码 sudo 访问权限:

您可以添加到 /etc/sudoers 文件:

admin ALL=(ALL:ALL) NOPASSWD:ALL