Ansible 与主机的共享连接已关闭

Ansible 与主机的共享连接已关闭,ansible,Ansible,我正在尝试为某些任务更改用户,但无法使其工作。关闭与主机的共享连接时出错 这是我的剧本: cat test1.yml - hosts: hcmbox tasks: - name: Find out my identity Bourne command: "whoami" register: idoutput become: true become_user: ebs1 - debug: msg="{{ idoutput.std

我正在尝试为某些任务更改用户,但无法使其工作。关闭与主机的共享连接时出错

这是我的剧本:

cat test1.yml

- hosts: hcmbox
  tasks:
    - name: Find out my identity Bourne
      command: "whoami"
      register: idoutput
      become: true
      become_user: ebs1

    - debug: msg="{{ idoutput.stdout }}"

我得到这个错误:

ansible-playbook -i inventory test1.yml                       

PLAY [hcmbox] *************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************
ok: [srvdb1.localdomain]

TASK [Find out my identity Bourne] ****************************************************************************************************************************************************
fatal: [srvdb1.localdomain]: FAILED! => {"changed": false, "module_stderr": "Shared connection to srvdb1.localdomain closed.\r\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP ****************************************************************************************************************************************************************************
srvdb1.localdomain    : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
从剧本中删除以下两行

      become: true
      become_user: ebs1
然后再次执行,以下是输出:

PLAY [hcmbox] *************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************
ok: [srvdb1.localdomain]

TASK [Find out my identity Bourne] ****************************************************************************************************************************************************
changed: [srvdb1.localdomain]

TASK [debug] **************************************************************************************************************************************************************************
ok: [srvdb1.localdomain] => {
    "msg": "oracle"
}

PLAY RECAP ****************************************************************************************************************************************************************************
srvdb1.localdomain    : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
在我看来,信任和一切都很好:

[oracle@ansctrlsrv epd3]$ ansible all -i 'srvdb1,' -m command -a 'whoami' -u ebs1

srvdb1 | CHANGED | rc=0 >>
ebs1

即使ssh也很好,我检查过了

[oracle@ansctrlsrv epd3]$ ssh ebs1@srvdb1
Last login: Tue Feb  4 10:35:51 2020 from ansctrlsrv.localdomain
[ebs1@srvdb1 ~]$ 
我不知道为什么会出现此错误:
到srvdb1.localdomain的共享连接已关闭

当我使用-vvv运行时,我看到的是:

ansible-playbook -i inventory -vvv test3.yml 
ansible-playbook 2.8.4
  config file = /stage/ap/ansible/epd3/ansible.cfg
  configured module search path = [u'/oracle/app/oracle/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible-playbook
  python version = 2.7.5 (default, Aug  7 2019, 08:19:52) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39.0.1)]
Using /stage/ap/ansible/epd3/ansible.cfg as config file
host_list declined parsing /stage/ap/ansible/epd3/inventory as it did not pass it's verify_file() method
script declined parsing /stage/ap/ansible/epd3/inventory as it did not pass it's verify_file() method
auto declined parsing /stage/ap/ansible/epd3/inventory as it did not pass it's verify_file() method
Parsed /stage/ap/ansible/epd3/inventory inventory source with ini plugin

PLAYBOOK: test3.yml *******************************************************************************************************************************************************************
1 plays in test3.yml

PLAY [hcmbox] *************************************************************************************************************************************************************************
META: ran handlers

TASK [command] ************************************************************************************************************************************************************************
task path: /stage/ap/ansible/epd3/test3.yml:10
<dbsrv1.localdomain> ESTABLISH SSH CONNECTION FOR USER: None
<dbsrv1.localdomain> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/oracle/app/oracle/.ansible/cp/9c1b54644d dbsrv1.localdomain '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<dbsrv1.localdomain> (0, '/oracle/app/oracle\n', '')
<dbsrv1.localdomain> ESTABLISH SSH CONNECTION FOR USER: None
<dbsrv1.localdomain> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/oracle/app/oracle/.ansible/cp/9c1b54644d dbsrv1.localdomain '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /var/tmp/ansible-tmp-1580841289.87-193361522034615 `" && echo ansible-tmp-1580841289.87-193361522034615="` echo /var/tmp/ansible-tmp-1580841289.87-193361522034615 `" ) && sleep 0'"'"''
<dbsrv1.localdomain> (0, 'ansible-tmp-1580841289.87-193361522034615=/var/tmp/ansible-tmp-1580841289.87-193361522034615\n', '')
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py
<dbsrv1.localdomain> PUT /oracle/app/oracle/.ansible/tmp/ansible-local-23567JjjVQn/tmpwYZDSF TO /var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py
<dbsrv1.localdomain> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/oracle/app/oracle/.ansible/cp/9c1b54644d '[dbsrv1.localdomain]'
<dbsrv1.localdomain> (0, 'sftp> put /oracle/app/oracle/.ansible/tmp/ansible-local-23567JjjVQn/tmpwYZDSF /var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py\n', '')
<dbsrv1.localdomain> ESTABLISH SSH CONNECTION FOR USER: None
<dbsrv1.localdomain> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/oracle/app/oracle/.ansible/cp/9c1b54644d dbsrv1.localdomain '/bin/sh -c '"'"'setfacl -m u:ebs1:r-x /var/tmp/ansible-tmp-1580841289.87-193361522034615/ /var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py && sleep 0'"'"''
<dbsrv1.localdomain> (0, '', '')
<dbsrv1.localdomain> ESTABLISH SSH CONNECTION FOR USER: None
<dbsrv1.localdomain> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/oracle/app/oracle/.ansible/cp/9c1b54644d -tt dbsrv1.localdomain '/bin/sh -c '"'"'sudo -H -S -n  -u ebs1 /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-qtuzljmaohdcqewvlstmcepjcdwdxsiy ; /usr/bin/python /var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<dbsrv1.localdomain> (1, '', 'Shared connection to dbsrv1.localdomain closed.\r\n')
<dbsrv1.localdomain> Failed to connect to the host via ssh: Shared connection to dbsrv1.localdomain closed.
<dbsrv1.localdomain> ESTABLISH SSH CONNECTION FOR USER: None
<dbsrv1.localdomain> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/oracle/app/oracle/.ansible/cp/9c1b54644d dbsrv1.localdomain '/bin/sh -c '"'"'rm -f -r /var/tmp/ansible-tmp-1580841289.87-193361522034615/ > /dev/null 2>&1 && sleep 0'"'"''
<dbsrv1.localdomain> (0, '', '')
failed: [dbsrv1.localdomain] (item=ebs1) => {
    "ansible_loop_var": "item", 
    "changed": false, 
    "item": "ebs1", 
    "module_stderr": "Shared connection to dbsrv1.localdomain closed.\r\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

PLAY RECAP ****************************************************************************************************************************************************************************
dbsrv1.localdomain    : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

ansible剧本-i目录-vvv test3.yml
ansible剧本2.8.4
配置文件=/stage/ap/ansible/epd3/ansible.cfg
配置的模块搜索路径=[u'/oracle/app/oracle/.ansible/plugins/modules',u'/usr/share/ansible/plugins/modules']
ansible python模块位置=/usr/lib/python2.7/site-packages/ansible
可执行文件位置=/bin/ansible playbook
python版本=2.7.5(默认值,2019年8月7日,08:19:52)[GCC 4.8.5 20150623(Red Hat 4.8.5-39.0.1)]
使用/stage/ap/ansible/epd3/ansible.cfg作为配置文件
主机列表拒绝解析/stage/ap/ansible/epd3/inventory,因为它没有通过其verify\u file()方法
脚本拒绝解析/stage/ap/ansible/epd3/inventory,因为它没有通过其verify_file()方法
自动拒绝解析/stage/ap/ansible/epd3/inventory,因为它没有通过其verify_file()方法
使用ini插件解析/stage/ap/ansible/epd3/库存源
剧本:test3.yml*******************************************************************************************************************************************************************
1在test3.yml中播放
播放[hcmbox]*************************************************************************************************************************************************************************
META:ran处理程序
任务[命令]************************************************************************************************************************************************************************
任务路径:/stage/ap/ansible/epd3/test3.yml:10
为用户建立SSH连接:无
SSH:EXEC SSH-C-o ControlMaster=auto-o ControlPersist=60s-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi with mic、gssapi-keyex、基于主机、公钥-o PasswordAuthentication=no-o ConnectTimeout=10-o ControlPath=/oracle/app/oracle/.ansible/cp/9c14644d dbsrv1.localdomain'/bin/sh-C''echo~&sleep 0''
(0,'/oracle/app/oracle\n','')
为用户建立SSH连接:无
SSH:EXEC SSH-C-o ControlMaster=auto-o ControlPersist=60s-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi with mic、gssapi-keyex、基于主机、公钥-o PasswordAuthentication=no-o ConnectTimeout=10-o ControlPath=/oracle/app/oracle/.ansible/cp/9c14644d dbsrv1.localdomain'/bin/sh-C'''(umask 77&&mkdir-p“`echo/var/tmp/ansible-tmp-1580841289.87-193361522034615`&&echo-ansible-tmp-1580841289.87-193361522034615=“`echo/var/tmp/ansible-tmp-1580841289.87-193361522034615`&&sleep 0'”
(0,‘ansible-tmp-1580841289.87-193361522034615=/var/tmp/ansible-tmp-1580841289.87-193361522034615\n’,“”)
使用模块文件/usr/lib/python2.7/site-packages/ansible/modules/commands/command.py
将/oracle/app/oracle/.ansible/tmp/ansible-local-23567jjvqn/tmpwYZDSF放到/var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py
SSH:EXEC sftp-b--C-o ControlMaster=auto-o ControlPersist=60s-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi with mic、gssapi-keyex、基于主机、公钥-o PasswordAuthentication=no-o ConnectTimeout=10-o ControlPath=/oracle/app/oracle/.ansible/cp/9c1b54644d'[dbsrv1.localdomain]'
(0,'sftp>put/oracle/app/oracle/.ansible/tmp/ansible-local-23567jjvqn/tmpwYZDSF/var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py\n','')
为用户建立SSH连接:无
SSH:EXEC SSH-C-o ControlMaster=auto-o ControlPersist=60s-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi with mic、gssapi-keyex、基于主机、公钥-o PasswordAuthentication=no-o ConnectTimeout=10-o ControlPath=/oracle/app/oracle/.ansible/cp/9c14644d dbsrv1.localdomain'/bin/sh-C''“'setfacl-mu:ebs1:r-x/var/tmp/ansible-tmp-1580841289.87-193361522034615//var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py&&sleep 0'”
(0, '', '')
为用户建立SSH连接:无
SSH:EXEC SSH-C-o ControlMaster=auto-o ControlPersist=60s-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi with mic、gssapi-keyex、基于主机、公钥-o PasswordAuthentication=no-o ConnectTimeout=10-o ControlPath=/oracle/app/oracle/.ansible/cp/9c14644d-tt dbsrv1.localdomain'/bin/sh-C''"sudo-H-S-n-u ebs1/bin/sh-c""""""""""echo"成为成功的qtuzljmaohdcquewvlstmcpdxsiy"/usr/bin/python/var/tmp/ansible-tmp-1580841289.87-193361522034615/AnsiballZ_command.py''''和&sleep 0'''
升级成功
(1,,'到dbsrv1.localdomain的共享连接已关闭。\r\n')
无法通过ssh连接到主机:与dbsrv1的共享连接。localdomain已关闭。
为用户建立SSH连接:无
SSH:EXEC SSH-C-o ControlMaster=auto-o ControlPersist=60s-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi with mic,gssapi-keyex,hostbased,publickey-o PasswordAuthentication=no-o ConnectTimeout=10-o ControlPath=/oracle/app/oracle/.ansible/cp/9c14644d dbsrv1.localdomain'/bin/sh-C''“rm-f-r/var/tmp/ansible-tmp-1580841289.87-193361522034615/>/dev/null 2>&1和睡眠0”
(0, '', '')
失败:[dbsrv1.localdomain](项=ebs1)=>{
“ansible_loop_var”:“项目”,
“更改”:错误,
“项目”:“ebs1”,
“module_stderr”:“与dbsrv1.localdomain的共享连接已关闭。\r\n”,
“模块”:“,
“msg”:“模块故障\n请参阅stdout/stde