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

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

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 }}’

`

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?

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

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
[server2]
http://www.blah2.com

Now you have a playbook:

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:

  shell: /etc/ansible/start_video.sh {{lookup('pipe', 'grep -A1 ' +
inventory_hostname + ' /etc/ansible/task/url.conf|tail -n 1'}}

^ that should work

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!