How to pass a variable to an accessible game on the command line?

I am new to features and wonder how to do this since the following does not work.

ansible-playbook -i '10.0.0.1,' yada-yada.yml --tags 'loaddata' django_fixtures="tile_colors" 

Where django_fixtures is my variable.

+172
variables command-line command-line-arguments ansible ansible-playbook
Jun 05 '15 at 8:42
source share
10 answers

Reading the documents I find the section Transferring Variables on the Command Line , which give this example:

 ansible-playbook release.yml --extra-vars "version=1.23.45 other_variable=foo" 

Other examples demonstrate how to load from a JSON string (โ‰ฅ 1.2 ) or a file (โ‰ฅ 1.3 )

+252
Jun 05 '15 at 8:47
source share

Other answers indicate how to pass command line variables, but not how to access them, so if you do:

 --extra-vars "version=1.23.45 other_variable=foo" 

In your yml file, you assign them to the covered variable variables, doing something like:

 vars: my_version: "{{ version }}" my_other_variable: {{ other_variable }} 

An alternative to using command line arguments is to use environment variables that are already defined in your session, you can reference them in your similar yml files as follows:

 vars: my_version: "{{ lookup('env', 'version') }}" my_other_variable: {{ lookup('env', 'other_variable') }} 
+126
Feb 20 '17 at 15:06
source share
 ansible-playbook release.yml -e "version=1.23.45 other_variable=foo" 
+37
Jun 22 '16 at 8:07
source share

You can use the --extra-vars . See documents

+30
Jun 05 '15 at 8:46
source share

For some reason, none of the above answers worked for me. Since I need to pass a few extra vars to my book in Ansbile 2.2.0, here is how I earned it (note the -e option before each var):

 ansible-playbook site.yaml -i hostinv -e firstvar=false -e second_var=value2 
+25
Oct 20 '16 at 8:34
source share
 ansible-playbook test.yml --extra-vars "arg1=${var1} arg2=${var2}" 

In yml file you can use them like this

 --- arg1: "{{ var1 }}" arg2: "{{ var2 }}" 

Also, --extra-vars and -e same, you can use one of them.

+9
Sep 02 '18 at 16:18
source share
 ansible-playbook release.yml --extra-vars "username=hello password=bye" #you can now use the above command anywhere in the playbook as an example below: tasks: - name: Create a new user in Linux shell: useradd -m -p {{username}} {{password}}" 
+1
Feb 24 '19 at 8:13
source share

ansible-playbok -i <inventory> <playbook-name> -e "proc_name=sshd"

You can use the above command in the following books.

 --- - name: Service Status gather_facts: False tasks: - name: Check Service Status (Linux) shell: pgrep "{{ proc_name }}" register: service_status ignore_errors: yes debug: var=service_status.rc' 
0
Feb 17 '19 at 9:33
source share
  s3_sync: bucket: ansible-harshika file_root: "{{ pathoftsfiles }}" validate_certs: false mode: push key_prefix: "{{ folder }}" 

it uses variables with the names 'pathoftsfiles' and 'folder'. Now the value of this variable can be set by the command below

 sudo ansible-playbook multiadd.yml --extra-vars "pathoftsfiles=/opt/lampp/htdocs/video/uploads/tsfiles/$2 folder=nitesh" 

Note. Do not use quotation marks when passing variable values โ€‹โ€‹to shell commands

0
May 14 '19 at 19:51
source share

This also worked for me if you want to use shell environment variables:

ansible-playbook -i "localhost," ldap.yaml --extra-vars="LDAP_HOST={{ lookup('env', 'LDAP_HOST') }} clustername=mycluster env=dev LDAP_USERNAME={{ lookup('env', 'LDAP_USERNAME') }} LDAP_PASSWORD={{ lookup('env', 'LDAP_PASSWORD') }}"

0
Jul 22 '19 at 10:33
source share



All Articles