From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Using variables - Ansible Tutorial
From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Using variables
- [Instructor] Variables are used in all but the most simple playbooks that I create. They add reusability and flexibility, which can make automation much more efficient. I'm going to use the same simple-playbook from the last section and build on it. I'll create a new user, but I'll utilize variables. I'll duplicate my playbook and name it variables.yml. I'll modify the name portion down here in the task to use a variable named new_user. Double mustaches, double quotes, new_user. I could use the playbook as is if I were to run the playbook and present the new_user variable as an extra var like so, ansible-playbook -i, specifying the inventory again. Now, it's going to be -e for the new vars, new_user=test1. And then the playbook, variables.yml. So as demonstrated, even though I didn't define the contents of new variable in the playbook, it was passed as an extra var and ran successfully. There are currently 22 different levels of variable precedence in Ansible, which sounds…
Contents
-
-
-
(Locked)
Installing collections2m 20s
-
Construct a simple playbook4m 19s
-
(Locked)
Using variables5m 7s
-
(Locked)
Using loops2m 45s
-
(Locked)
Adding conditionals4m 57s
-
(Locked)
Utilizing blocks3m 49s
-
(Locked)
Exploring templates4m 29s
-
(Locked)
Discovering handlers2m 23s
-
(Locked)
Using tags2m 53s
-
(Locked)
Testing plays with check mode2m 15s
-
(Locked)
Conditional failure with assert2m 20s
-
(Locked)
Failure and change control2m 32s
-
(Locked)
Nesting loops3m 29s
-
(Locked)
Creating dynamic inventory files3m 7s
-
(Locked)
Challenge: Create a complex playbook1m 17s
-
Solution: Verify the complex playbook2m 52s
-
(Locked)
-
-
-
-