首页 文章

ansible命令/ shell模块似乎没有评估和选择参数

提问于
浏览
3

我在一个角色里面运行一个ansible playbook(ansible V1.9.4),我正在尝试安装并运行带参数的命令但是当我尝试从任务 - name: Run installation of cht agent 上的Anisble-playbook执行时,它没有't run properly but in fact hangs during the execution of this task. In contrary, when I ran the command manually on the ec2 host itself, it ran perfectly without any issues. What I observed is there might be parameters not properly passed from ansible-play'的任务主持人,但我可能错了 .

这是我正在运行的剧本,

---
# tasks file for cloudhealth-agent installation
- name: Download the agent
  command: wget https://s3.amazonaws.com/remote-collector/agent/v14/install_cht_perfmon.sh -O /tmp/install_cht_perfmon.sh

- name: Run installation of cht agent
  command: sh /tmp/install_cht_perfmon.sh 14 {{ cht_unique_registration_code }} aws
  args:
    creates: /opt/cht_perfmon
  sudo: yes
  register: install_cmd

- debug: var= {{ install_cmd | to_nice_yaml }}

我的剧本执行的输出在下面,

$ ansible-playbook -i inventory/ec2.py cloudhealth-agent.yml -vvv

PLAY [setup cloudhealth agent] ************************************************ 

GATHERING FACTS *************************************************************** 
<ip-172-27-0-189.eu-west-1.compute.internal> ESTABLISH CONNECTION FOR USER: ubuntu
<ip-172-27-0-189.eu-west-1.compute.internal> REMOTE_MODULE setup
<ip-172-27-0-189.eu-west-1.compute.internal> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=600s -o ForwardAgent=yes -o ConnectTimeout=30 -F ./ssh_config -o ControlPath="/Users/ming/.ansible/cp/%h-%r" -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 ip-172-27-0-189.eu-west-1.compute.internal /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1466754898.59-115321310845059 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1466754898.59-115321310845059 && echo $HOME/.ansible/tmp/ansible-tmp-1466754898.59-115321310845059'
<ip-172-27-0-189.eu-west-1.compute.internal> PUT /var/folders/ws/7l0c9mh95cddncp060gksz3m0000gn/T/tmpCtS3WG TO /home/ubuntu/.ansible/tmp/ansible-tmp-1466754898.59-115321310845059/setup
<ip-172-27-0-189.eu-west-1.compute.internal> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=600s -o ForwardAgent=yes -o ConnectTimeout=30 -F ./ssh_config -o ControlPath="/Users/ming/.ansible/cp/%h-%r" -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 ip-172-27-0-189.eu-west-1.compute.internal /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1466754898.59-115321310845059/setup; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1466754898.59-115321310845059/ >/dev/null 2>&1'
ok: [ip-172-27-0-189.eu-west-1.compute.internal]

TASK: [cloudhealth-agent | Download the agent] ******************************** 
<ip-172-27-0-189.eu-west-1.compute.internal> ESTABLISH CONNECTION FOR USER: ubuntu
<ip-172-27-0-189.eu-west-1.compute.internal> REMOTE_MODULE command wget https://s3.amazonaws.com/remote-collector/agent/v14/install_cht_perfmon.sh -O /tmp/install_cht_perfmon.sh
<ip-172-27-0-189.eu-west-1.compute.internal> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=600s -o ForwardAgent=yes -o ConnectTimeout=30 -F ./ssh_config -o ControlPath="/Users/ming/.ansible/cp/%h-%r" -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 ip-172-27-0-189.eu-west-1.compute.internal /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1466754904.34-271098190135647 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1466754904.34-271098190135647 && echo $HOME/.ansible/tmp/ansible-tmp-1466754904.34-271098190135647'
<ip-172-27-0-189.eu-west-1.compute.internal> PUT /var/folders/ws/7l0c9mh95cddncp060gksz3m0000gn/T/tmpbskJDx TO /home/ubuntu/.ansible/tmp/ansible-tmp-1466754904.34-271098190135647/command
<ip-172-27-0-189.eu-west-1.compute.internal> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=600s -o ForwardAgent=yes -o ConnectTimeout=30 -F ./ssh_config -o ControlPath="/Users/ming/.ansible/cp/%h-%r" -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 ip-172-27-0-189.eu-west-1.compute.internal /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1466754904.34-271098190135647/command; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1466754904.34-271098190135647/ >/dev/null 2>&1'
changed: [ip-172-27-0-189.eu-west-1.compute.internal] => {"changed": true, "cmd": ["wget", "https://s3.amazonaws.com/remote-collector/agent/v14/install_cht_perfmon.sh", "-O", "/tmp/install_cht_perfmon.sh"], "delta": "0:00:00.344186", "end": "2016-06-24 07:55:47.631705", "rc": 0, "start": "2016-06-24 07:55:47.287519", "stderr": "--2016-06-24 07:55:47--  https://s3.amazonaws.com/remote-collector/agent/v14/install_cht_perfmon.sh\nResolving s3.amazonaws.com (s3.amazonaws.com)... 54.231.34.80\nConnecting to s3.amazonaws.com (s3.amazonaws.com)|54.231.34.80|:443... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 10964 (11K) [application/x-sh]\nSaving to: ‘/tmp/install_cht_perfmon.sh’\n\n     0K ..........                                            100% 77.6M=0s\n\n2016-06-24 07:55:47 (77.6 MB/s) - ‘/tmp/install_cht_perfmon.sh’ saved [10964/10964]", "stdout": "", "warnings": ["Consider using get_url module rather than running wget"]}

TASK: [cloudhealth-agent | Run installation of cht agent] ********************* 
<ip-172-27-0-189.eu-west-1.compute.internal> ESTABLISH CONNECTION FOR USER: ubuntu
<ip-172-27-0-189.eu-west-1.compute.internal> REMOTE_MODULE command creates=/opt/cht_perfmon sh /tmp/install_cht_perfmon.sh 14 123xxx-123xxx-abcxxx-abcxxx aws
<ip-172-27-0-189.eu-west-1.compute.internal> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=600s -o ForwardAgent=yes -o ConnectTimeout=30 -F ./ssh_config -o ControlPath="/Users/ming/.ansible/cp/%h-%r" -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 ip-172-27-0-189.eu-west-1.compute.internal /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1466754907.35-97872289930978 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1466754907.35-97872289930978 && echo $HOME/.ansible/tmp/ansible-tmp-1466754907.35-97872289930978'
<ip-172-27-0-189.eu-west-1.compute.internal> PUT /var/folders/ws/7l0c9mh95cddncp060gksz3m0000gn/T/tmppMq1Of TO /home/ubuntu/.ansible/tmp/ansible-tmp-1466754907.35-97872289930978/command
<ip-172-27-0-189.eu-west-1.compute.internal> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=600s -o ForwardAgent=yes -o ConnectTimeout=30 -F ./ssh_config -o ControlPath="/Users/ming/.ansible/cp/%h-%r" -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 ip-172-27-0-189.eu-west-1.compute.internal /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=ayckvspsdjyouwajusfxzdiepomhqzil] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-ayckvspsdjyouwajusfxzdiepomhqzil; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1466754907.35-97872289930978/command; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1466754907.35-97872289930978/ >/dev/null 2>&1'"'"''
^CERROR: interrupted

注意到最后一行它显示了一堆空引号, -u root /bin/sh -c '"'"' . 在我看来,命令语法没有正确传递参数 . 有关如何解析或提供正确的命令行以在远程主机上执行的任何想法或建议?

2 回答

  • 1

    你应该使用shell - Execute commands in nodes

    shell模块获取命令名称,后跟空格分隔的参数列表 . 它几乎与命令模块完全相同,但通过远程节点上的shell(/ bin / sh)运行命令 .

    - name: Run installation of cht agent
      shell: bash -c "/tmp/install_cht_perfmon.sh 14 {{ cht_unique_registration_code }} aws"
      args:
        creates: /opt/cht_perfmon
      sudo: yes
      register: install_cmd
    

    要么:

    - name: Run installation of cht agent
      shell: /tmp/install_cht_perfmon.sh 14 {{ cht_unique_registration_code }} aws
      args:
        creates: /opt/cht_perfmon
      sudo: yes
      register: install_cmd
    
  • 0

    我解决了这个问题 . 它不是我在命令或shell上的ansible语法,但是我传递了错误的API密钥,导致'install_cht_perfomsh'无法使用错误的密钥进行处理 .

    〜感谢您的帮助

相关问题