无法通过Ansible打印完整输出

时间:2016-10-11 20:05:28

标签: ansible

我有一个需要远程执行的命令。

find /opt/cac/CI/release/releases -name "*.tar" -exec md5sum {} \;

完整的输出是::

e5af5514887e8cbc08815936558a3220  /opt/cac/CI/release/releases/permission/4.00.00.04/CXP_902_8059_4.00.00.04_20161007-131208.tar
d35eae58399770627ba42f5b538a9cab  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20160927-052332.tar
784d035f9959f6a3006aaab202c13015  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20160927-060837.tar
3234cc8944c1d26c1ff0fac844ae8674  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20160927-062202.tar
431368042e9f5e62de37787cd2d05b08  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20161008-173030.tar 

我正在尝试使用Ansible做同样的事情:

- hosts: tmoittecac
  tasks:
    - name: Report md5sum of Release files.
      shell: find /opt/cac/CI/release/releases -name "*.tar" -exec md5sum {} \;
      register: pre_md5_check
      tags: a

    - debug: msg={{ pre_md5_check.stdout_lines }}
      tags: b

但我得到的输出是::

TASK: [debug msg={{ pre_md5_check.stdout_lines }}] **************************** 
ok: [tmoittecac] => {
    "msg": "['e5af5514887e8cbc08815936558a3220  /opt/cac/CI/release/releases/permission/4.00.00.04/CXP_902_8059_4.00.00.04_20161007-131208.tar',"
}

我只获得实际输出的第一行。

以详细模式运行playbook给了我。

TASK: [Report md5sum of Release files.] *************************************** 
<147.128.72.59> ESTABLISH CONNECTION FOR USER: local
<147.128.72.59> REMOTE_MODULE command find /opt/cac/CI/release/releases -name "*.tar" -exec md5sum {} \; #USE_SHELL
<147.128.72.59> EXEC sshpass -d7 ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=local -o ConnectTimeout=10 147.128.72.59 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1476216014.64-144818429840055 && echo $HOME/.ansible/tmp/ansible-tmp-1476216014.64-144818429840055'
<147.128.72.59> PUT /tmp/tmpm6eavD TO /opt/home/local/.ansible/tmp/ansible-tmp-1476216014.64-144818429840055/command
<147.128.72.59> EXEC sshpass -d7 ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o User=local -o ConnectTimeout=10 147.128.72.59 /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /opt/home/local/.ansible/tmp/ansible-tmp-1476216014.64-144818429840055/command; rm -rf /opt/home/local/.ansible/tmp/ansible-tmp-1476216014.64-144818429840055/ >/dev/null 2>&1'
changed: [tmoittecac] => {"changed": true, "cmd": "find /opt/cac/CI/release/releases -name \"*.tar\" -exec md5sum {} \\;", "delta": "0:00:01.172660", "end": "2016-10-12 03:53:14.020937", "rc": 0, "start": "2016-10-12 03:53:12.848277", "stderr": "", "stdout": "e5af5514887e8cbc08815936558a3220  /opt/cac/CI/release/releases/permission/4.00.00.04/CXP_902_8059_4.00.00.04_20161007-131208.tar\nd35eae58399770627ba42f5b538a9cab  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20160927-052332.tar\n784d035f9959f6a3006aaab202c13015  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20160927-060837.tar\n3234cc8944c1d26c1ff0fac844ae8674  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20160927-062202.tar\n431368042e9f5e62de37787cd2d05b08  /opt/cac/CI/release/releases/privacyvault/4.08.01.00/CXP_902_8185_4.08.01.00_20161008-173030.tar\n7f637400276cb25f7f3b2f869d915dc7  /opt/cac/CI/release/releases/notification/4.00.00.03/CXP_902_8347_4.00.00.03_20160928-070050.tar\nfa4a0aea0c096c703f2a9a741d2d1152  /opt/cac/CI/release/releases/user-preference/4.08.01.00/CXP_902_8717_4.08.01.00_20160929-034340.tar\n34f084c617f49123fc0edef358d15784  /opt/cac/CI/release/releases/captcha/2.08.01.00/CXP_902_8881_2.08.01.00_20160929-043449.tar\n2041d873f0619f1c9a4c8e419156753e  /opt/cac/CI/release/releases/consumerProfile/3.08.02.00/CXP_902_8057_3.08.02.00_20161008-063249.tar\n7a0a9efe4232eebbb5c05e5b84fb6bec  /opt/cac/CI/release/releases/consumerProfile/3.08.02.00/CXP_902_8057_3.08.02.00_20161008-071824.tar", "warnings": []}

TASK: [debug msg={{ pre_md5_check.stdout_lines }}] **************************** 
<147.128.72.59> ESTABLISH CONNECTION FOR USER: local
ok: [tmoittecac] => {
    "msg": "['e5af5514887e8cbc08815936558a3220  /opt/cac/CI/release/releases/permission/4.00.00.04/CXP_902_8059_4.00.00.04_20161007-131208.tar',"
}

这些是我遗失的吗?

更多信息::

  tasks:
   - name:  Check md5sums of WAR files.
     shell:  find /opt/cac/CI/release/releases -name "*.tar" -exec md5sum {} \;
     register: MD5SUMS
     tags: a

   - name: Output md5sum of WAR files.
     debug: var={{ MD5SUMS }}
     tags: b

输出::

GATHERING FACTS *************************************************************** 
ok: [tmoittecac]

TASK: [Check md5sums of WAR files.] ******************************************* 
changed: [tmoittecac]

TASK: [Output md5sum of WAR files.] ******************************************* 
ok: [tmoittecac] => {
    "var": {
        "{'changed':": "{'changed':"
    }
}

PLAY RECAP ******************************************************************** 
tmoittecac                 : ok=3    changed=1    unreachable=0    failed=0   

Ansible版本是:

ansible --version
ansible 1.9.4

1 个答案:

答案 0 :(得分:0)

通过将Ansible版本升级到2.1来解决问题。