简体   繁体   English

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

[英]ansible command / shell module doesn't seem to evaluate and pick parameters

I am running an ansible playbook (ansible V1.9.4) inside of a role which I'm trying to install and running a command with parameters but when I try to execute from from Anisble-playbook on task - name: Run installation of cht agent , it doesn't run properly but in fact hangs during the execution of this task. 我在一个角色里面运行一个ansible playbook(ansible V1.9.4),我正在尝试安装并运行带参数的命令,但是当我尝试从任务上的Anisble-playbook执行时- 名称:运行cht agent的安装 ,它不能正常运行,但实际上在执行此任务期间会挂起。 In contrary, when I ran the command manually on the ec2 host itself, it ran perfectly without any issues. 相反,当我在ec2主机上手动运行命令时,它运行完美,没有任何问题。 What I observed is there might be parameters not properly passed from ansible-play's task to the host, but I might be wrong on it. 我观察到的可能是从ansible-play的任务没有正确传递给主机的参数,但我可能错了。

This is my playbook that I'm running, 这是我正在运行的剧本,

---
# 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 }}

The output of my playbook execute is at below, 我的剧本执行的输出在下面,

$ 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

Noticed the last line it shown an empty bunch of quotes, -u root /bin/sh -c '"'"' . 注意到最后一行它显示了一串空引号, -u root /bin/sh -c '"'"' This seems to me the command syntax is not passing the parameters properly. 在我看来,命令语法没有正确传递参数。 Any idea or suggestion on how to resolve or feed the proper command line to execute at remote host? 有关如何解析或提供正确的命令行以在远程主机上执行的任何想法或建议?

I got this issue resolved. 我解决了这个问题。 It wasn't with my ansible syntax on command or shell, but I was passing the wrong API key that it resulted the 'install_cht_perfomsh' not able to process with the wrong key. 它不是我在命令或shell上的ansible语法,但是我传递了错误的API密钥,导致'install_cht_perfomsh'无法使用错误的密钥进行处理。

~thanks for help 〜感谢您的帮助

You should use the shell - Execute commands in nodes : 您应该使用shell - 节点中的Execute命令

The shell module takes the command name followed by a list of space-delimited arguments. shell模块获取命令名称,后跟空格分隔的参数列表。 It is almost exactly like the command module but runs the command through a shell (/bin/sh) on the remote node. 它几乎与命令模块完全相同,但通过远程节点上的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

or: 要么:

- 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM