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.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e24841e2-7d47-409f-b1d8-388a15445cee%40googlegroups.com.

Reply via email to