From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Registering variables
From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks
Registering variables
- [Instructor] In BASH and some other languages we can run commands and have the output assigned to a variable such as this. This runs the command whoami and assigns the output to the variable named NAME. We can do something similar with Ansible variables by registering the result of a task as a variable. When you execute a task and save the returned value in a variable for later use, you create a registered variable. For instance, this task will use a shell module to run the GREP command to count the number of authentication failures in /var/log/messages. The standard out will be stored in the message_contents variable. Once we have the data in the variable, we can create a condition that acts on it. We won't go into conditions right now, as it's not on the scope of this particular video, but this is the syntax. Our condition runs a script called lockdown.sh when the value in the message_contents variable is equal to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.