Pass variable to ansible playbook through command line

+1 vote
How do I pass variables to ansible playbook through command line?
Jan 10, 2019 in Ansible by Rahul
14,379 views

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, 2019 by Bobin

selected May 7, 2019 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 10, 2019 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, 2019 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, 2019 by Jinu
Thanks. It saved a lot of time for me.

Hello,

Glad to hear that!! If you found this is helpful you can upvote the answer!!

Thank You!

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

How to create a variable in Ansible Playbook?

Hi@akhtar, Variable in playbooks are very similar to using variables in ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,460 points
1,317 views
0 votes
1 answer

How to see any module details in Ansible from the command line?

Hi@akhtar, Ansible has a very attractive command named ...READ MORE

answered Aug 11, 2020 in Ansible by MD
• 95,460 points
23,701 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,005 views
+2 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, 2019 in Ansible by Vaishu
17,618 views
0 votes
1 answer

Execute a command using ansible playbook

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

answered Jan 17, 2019 in Ansible by Sameer
5,427 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP