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.

> On 06-Nov-2019, at 4:34 PM, Abhijeet Kasurde <[email protected]> wrote:
> 
> Hi Sandeep,
> 
> Did you get it working ? 
> 
> On Wednesday, November 6, 2019 at 10:09:43 AM UTC+5:30, Abhijeet Kasurde 
> wrote:
> 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,
> 
> On Tuesday, November 5, 2019 at 4:41:34 PM UTC+5:30, Sandeep Sridhar wrote:
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/32c51110-fa7b-44f6-9b4e-f80500b1e469%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/32c51110-fa7b-44f6-9b4e-f80500b1e469%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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/ED83B37F-65A4-4624-BFD7-B82A6F38034E%40gmail.com.

Reply via email to