# When running the shell module in a playbook, how to pass a url to the script?

**URL:** <https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412>\
**Category:** Ansible Project\
**Created:** [June 5, 2015, 1:39am UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412 "2015-06-05T01:39:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emil\_Kacperski1](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Emil\_Kacperski1](https://forum.ansible.com/u/Emil_Kacperski1)\
**Post date:** [June 5, 2015, 1:39am UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412/1 "2015-06-05T01:39:28Z")

</div>

Hello,

If I am running the shell module to run a script and I want to pass a url into the script how would I do this? Can’t use a variable because it’s not a dict word?

For example the script is :

echo $url \> test.output

The playbook has a task running :

shell echo.sh

If I have a configuration file where the url’s are contained, how can I pass it to the script?

Thanks!

Emil

---

<div class="post-metadata">

**Author:** ![user64](https://avatars.discourse-cdn.com/v4/letter/u/dec6dc/32.png) [@user64](https://forum.ansible.com/u/user64)\
**Post date:** [June 5, 2015, 3:58am UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412/2 "2015-06-05T03:58:43Z")

</div>

As I understart u want something like this?

`

- name: 1  
shell: ‘date’  
register: echo0\_result
- name: 2  
shell: ‘echo Current date is - {{ echo0\_result.stdout }}’  
register: echo1\_result
- name: 3  
debug: msg=‘1st result is {{ echo0\_result.stdout }}, 2nd is {{ echo1\_result.stdout }}’

`

---

<div class="post-metadata">

**Author:** ![Emil\_Kacperski1](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Emil\_Kacperski1](https://forum.ansible.com/u/Emil_Kacperski1)\
**Post date:** [June 5, 2015, 4:40pm UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412/3 "2015-06-05T16:40:37Z")

</div>

Not quite. basically right now I have 10 individual servers where I run a script to bring up a chromium browser output is hdmi. Basically  
I have a videowall with monitors. Each server has the script and a local screen.conf file which contains the url string.

But instead of logging into each server to change the url or restart the script I want to do this with ansible.

The script and everything is running just fine using the script. Except of course I want a screen.conf to reside on the ansible server  
and not on the remote server. So that when I run the restart script the url is passed into the script and everything is controlled from  
the ansible server logging into the remote servers.

Basically I am not sure how to pass on the url to the remote server script.

The example I gave is very basic, just assume that the echo.sh is located on the remote server and the url file is located on the ansible  
server. Let’s assume screen.conf, so when I run the echo.sh using the shell module I need it to grab the url from the screen.conf  
and then pass it to the echo.sh script where it’s referenced as $url.

Does this make sense?

---

<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:** [June 5, 2015, 6:51pm UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412/4 "2015-06-05T18:51:55Z")

</div>

if the configuration file is local to the 'master', you can use a lookup:

lookup('pipe', 'cat /file/with/url')

if it is remote, backtick to do same

---

<div class="post-metadata">

**Author:** ![Emil\_Kacperski1](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Emil\_Kacperski1](https://forum.ansible.com/u/Emil_Kacperski1)\
**Post date:** [June 5, 2015, 7:29pm UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412/5 "2015-06-05T19:29:03Z")

</div>

Are we now going away from Ansible? Ok on ansible you have a /etc/ansible/task/url.conf file contains:

[server1]  
[http://www.blah.com](http://www.blah.com)  
[server2]  
[http://www.blah2.com](http://www.blah2.com)

Now you have a playbook:

---

<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:** [June 5, 2015, 11:16pm UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412/6 "2015-06-05T23:16:21Z")

</div>

it would be easier if it were a host/group vars file or even a proper  
ini file (there is an ini lookup plugin in queue). But if that is what  
you have and assuming the caption is per inventory hostname:

&nbsp;&nbsp;shell: /etc/ansible/start\_video.sh {{lookup('pipe', 'grep -A1 ' +  
inventory\_hostname + ' /etc/ansible/task/url.conf|tail -n 1'}}

^ that should work

---

<div class="post-metadata">

**Author:** ![Emil\_Kacperski](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@Emil\_Kacperski](https://forum.ansible.com/u/Emil_Kacperski)\
**Post date:** [June 5, 2015, 11:32pm UTC](https://forum.ansible.com/t/when-running-the-shell-module-in-a-playbook-how-to-pass-a-url-to-the-script/18412/7 "2015-06-05T23:32:57Z")

</div>

Thanks Brian, will look into that and see if I can make it work.

Someone else brought up a very easy solution, simply have multiple config files on the ansible server and do a copy  
to the dest. It’s funny how I was so determined to get it done a certain way, while a simple solution was right  
in front of me.

Thanks all for the ideas!
