3
votes

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. 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's task to the host, but I might be wrong on it.

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 '"'"'. 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?

2
Ansible doesn't run commands directly through ssh, but creates temporary files that it runs (which can make debugging what it's doing a bit more difficult). While it's hanging, you can do a ps aux-type operation to find the process, and it'll show you exactly what's being run. My bet is that the script is waiting for interactive input from you for some reason or another. - Xiong Chiamiov
Another thing to check: have you tried hard-coding the value of cht_unique_registration_code in? That will tell you if the problem is with the command or with your variable definitions. - Xiong Chiamiov
Try shell module instead of command – they are different things in ansible. - Konstantin Suvorov

2 Answers

1
votes

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.

~thanks for help

0
votes

You should use the shell - Execute commands in nodes:

The shell module takes the command name followed by a list of space-delimited arguments. It is almost exactly like the command module but runs the command through a shell (/bin/sh) on the remote node.

- 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