Pass variable to ansible playbook through command line

+1 vote
How do I pass variables to ansible playbook through command line?
Jan 9 in Ansible by Rahul

4 answers to this question.

+2 votes
Best answer
ansible-playbook test.yml --extra-vars "arg1=${var1} arg2=${var2}"

Use is like this in the yml file:

arg1: "{{ var1 }}"
arg2: "{{ var2 }}"
answered May 7 by Bobin

selected May 7 by Kalgi
+1 vote

It is possible to set variables at the command line using the --extra-vars argument. Variables can be defined using a single quoted string (containing one or more variables) using one of the formats below

key=value format:

ansible-playbook release.yml --extra-vars "version=1.23.45 other_variable=foo"
answered Jan 9 by Ansi
+1 vote

You can also try this:

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

the -e flag here is the shard form for --extra-vars

answered May 7 by Manasi
+1 vote

Try this if you want to pass multiple variables:

ansible-playbook site.yaml -i hostinv -e firstvar=false -e second_var=value2
answered May 7 by Jinu

Related Questions In Ansible

0 votes
1 answer
0 votes
3 answers
0 votes
1 answer

Running ansible command on a single server when it is deployed to multiple servers

You can try the run_once attribute: Example from ...READ MORE

answered Jun 13, 2018 in Ansible by DareDev
• 6,810 points
0 votes
1 answer

Permission denied when running ansible playbook through jenkins

Jenkins uses it's own user to execute ...READ MORE

answered Jun 25, 2018 in Ansible by DareDev
• 6,810 points
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
0 votes
1 answer
0 votes
1 answer

Ansible playbook to wget a file

Hey @Celia, one recommendation, try not using ...READ MORE

answered Jan 16 in Ansible by Vaishu
0 votes
1 answer

Execute a command using ansible playbook

Hey @Reshma, You can use the URI ...READ MORE

answered Jan 17 in Ansible by Sameer