I'm looking for Ansible Tower equivalent approach of loading extra variables from file. Just like from cli with ...--extra-vars "@somefile.yml" parameters. Can this be done in Ansible Tower?
Asked
Active
Viewed 5,359 times
1 Answers
0
From the Tower you have several options:
- Under Job Templates use the Extra Variables option. This is the
--extra-vars
equivalent to the cli (Take into account that Tower is not cli and you cannot pass a file but you can copy/paste your file there) - Use Surveys
- Load the Var file from your playbook directly and make it "flexible" with a variable to be sent from a Survey like:
- name: Load a variable file based on Survey, or a default if not found.
include_vars: "{{ item }}"
with_first_found:
- "{{ firts_option }}.yaml"
- "{{ second_option }}.yaml"
- default.yaml

imjoseangel
- 3,543
- 3
- 22
- 30
-
1I think these leaves me with option 1 or 2 because option 3 doesn't work if I'd like to use var from the file in hosts: header of the play. Really hoped there is a way to pass file name via extra vars instead of copying its content. – av37 May 07 '18 at 15:43
-
Why not copying first that file from the host and then play with it locally? – imjoseangel May 07 '18 at 20:21
-
1Sorry, didn't get your idea... Our yaml files are in source code repo (git) from where ansible tower project downloads them to ansible host before running job template. What would be host and local in this case? – av37 May 08 '18 at 16:01
-
Is it possible to share what do you want to do in the hosts with those yaml to have an idea about what is the process followed? In my head I don't have any escenario that needs a copy to the remote servers. You can do anything from the Tower and "attack" to your hosts directly – imjoseangel May 08 '18 at 18:59
-
I've a control file (yaml) with bunch of true and false vars that control the flow of the master playbook roles/tasks. Few of them control on what group(s) of hosts a particular role should run e.g. stopServer. Whatever number of hosts get to run the role, the tasks must be executed concurrently. So, I'm trying to figure out how to construct "hosts:" header dynamically. – av37 May 10 '18 at 13:34
-
Why not adding with add_host module? It’s really useful and saves a lot of time and effort. – imjoseangel May 10 '18 at 18:41