# Passing an IP address of a host as an a command line argument to a bash script

**URL:** <https://forum.ansible.com/t/passing-an-ip-address-of-a-host-as-an-a-command-line-argument-to-a-bash-script/17105>\
**Category:** Ansible Project\
**Created:** [December 19, 2014, 11:37am UTC](https://forum.ansible.com/t/passing-an-ip-address-of-a-host-as-an-a-command-line-argument-to-a-bash-script/17105 "2014-12-19T11:37:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fazal-e-Rehman\_Khan](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@Fazal-e-Rehman\_Khan](https://forum.ansible.com/u/Fazal-e-Rehman_Khan)\
**Post date:** [December 19, 2014, 11:37am UTC](https://forum.ansible.com/t/passing-an-ip-address-of-a-host-as-an-a-command-line-argument-to-a-bash-script/17105/1 "2014-12-19T11:37:24Z")

</div>

Dear All,

My hosts file looks like this.

[client]  
192.168.1.23

[server]  
192.168.1.24

[exchange]  
192.168.1.25

In my playbook, I want to run a script on a remote machine (“client” in my case) which requires the IP address of the other remote machine (server) as an cmd line argument to that script. My playbook looks like this.

hosts: client  
tasks:

- shell: myscript.sh {{ server }} {{ somevalue }}

What should I do? Please help.

Regards,  
Fazal-e-Rehman Khan

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 19, 2014, 1:12pm UTC](https://forum.ansible.com/t/passing-an-ip-address-of-a-host-as-an-a-command-line-argument-to-a-bash-script/17105/2 "2014-12-19T13:12:16Z")

</div>

I believe you are looking for the inventory\_hostname variable.

I also tend to use this in combination with ansible\_ssh\_host for completeness, such as:

{{ ansible\_ssh\_host|default(inventory\_hostname) }}

---

<div class="post-metadata">

**Author:** ![Fazal-e-Rehman\_Khan](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@Fazal-e-Rehman\_Khan](https://forum.ansible.com/u/Fazal-e-Rehman_Khan)\
**Post date:** [December 19, 2014, 1:30pm UTC](https://forum.ansible.com/t/passing-an-ip-address-of-a-host-as-an-a-command-line-argument-to-a-bash-script/17105/3 "2014-12-19T13:30:52Z")

</div>

No I want to send the IP address of “server” as a command line argument to a script which is be run on “client”  
client and server are 2 separate nodes - not the host on which ansible is running.

{{ inventory\_hostname }} has all hosts in it. I’m looking for a particular host from the group “server” out of them.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 19, 2014, 2:47pm UTC](https://forum.ansible.com/t/passing-an-ip-address-of-a-host-as-an-a-command-line-argument-to-a-bash-script/17105/4 "2014-12-19T14:47:31Z")

</div>

as long as the server group only has 1 ip:

hosts: client  
tasks:  
&nbsp;&nbsp;&nbsp;- shell: myscript.sh {{ groups['server'] }} {{ somevalue }}

---

<div class="post-metadata">

**Author:** ![Fazal-e-Rehman\_Khan](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@Fazal-e-Rehman\_Khan](https://forum.ansible.com/u/Fazal-e-Rehman_Khan)\
**Post date:** [December 19, 2014, 5:12pm UTC](https://forum.ansible.com/t/passing-an-ip-address-of-a-host-as-an-a-command-line-argument-to-a-bash-script/17105/5 "2014-12-19T17:12:15Z")

</div>

Thank you so much Brian once again. 🙂
