issue with script module in ansible 2.8

32 views
Skip to first unread message

Sandeep Sridhar

unread,
Nov 5, 2019, 6:11:34 AM11/5/19
to Ansible Project

I have a shell script that is designed to run "virsh domifaddr <domain name> | grep ipv4 | awk '{print $4}'" on the remote host. From my ansible controller, the playbook calls this piece:

  • name: Find out the IP address of ucloud_vm_name
    script: /root/mltr_source_code/compute_ucloud_vm_ip.sh {{ ucloud_vm_name }}

The actual shell script is as follows:

ucloud_vm_name=$1
ucloud_vm_status=`virsh list --all | grep $ucloud_vm_name | awk '{print $3}'`
ucloud_vm_ip_file=/root/$ucloud_vm_name.ip
echo "ucloud_vm_status=$ucloud_vm_status"
if [ "$ucloud_vm_status" = "running" ]
then
   ucloud_vm_ip=`virsh domifaddr mini | grep ipv4 | awk '{print $4}'`
   if [ -f /root/$ucloud_vm_name.ip ]
   then
     rm -rf /root/$ucloud_vm_name.ip
   fi
   echo $ucloud_vm_ip > /root/$ucloud_vm_name.ip
elif [ "$ucloud_vm_status" = "shut off" ]
then
   echo "undercloud_vm is shut off"
else
   # do nothing
   echo "Have a beer"
fi

playbook runs fine without any errors. However, the IP address is never computed and written onto /root/$ucloud_vm_name.ip. The file content is empty after running the playbook.

Interestingly, if I execute the above shell script manually on the remote host, it just runs fine. Only if I execute from the ansible controller through script module, the content of /root/$ucloud_vm_name.ip is empty always.

Can you please help me with what is going wrong?

-Sandeep.


Abhijeet Kasurde

unread,
Nov 5, 2019, 11:39:43 PM11/5/19
to Ansible Project
Hi Sandeep,

Could you please provide -vvvv log for your playbook run ? Without that information it is very difficult to know what is wrong. I would recommend you to add more debugging statements in shell script before running via Ansible. btw, I see domain name hardcoded at "domifaddr" line (is that expected ?).

Thanks,

Abhijeet Kasurde

unread,
Nov 6, 2019, 6:04:20 AM11/6/19
to Ansible Project
Hi Sandeep,

Did you get it working ?

Sandeep Sridhar

unread,
Nov 6, 2019, 6:06:54 AM11/6/19
to ansible...@googlegroups.com
Hi Abhijeet, 

Sorry for the delayed response. We can close this thread. 

It was not working because, I wasn’t waiting enough for the VM to render an IP address when “virsh domifaddr” was executed. 

I just added a sleep 60 in the beginning of the shell script and things went fine after that. 

Thank you for your help on this. Really appreciate it. 

Greetings,
Sandeep.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/32c51110-fa7b-44f6-9b4e-f80500b1e469%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages