Ansible variables

Variables are the most simple of the potential customizations. With variables, we can define values that are going to be replaced in our playbooks. Let's take a look at the following playbook:

---- hosts: all  user: root  tasks:  - debug:    msg: "Hello {{ myName }}! I am {{ inventory_hostname }}"

Replace the content of tasks.yml with the snippet from earlier. There are two new symbols in our task. Also, our task is new: debug is used to output values from our variables into the terminal while executing the playbook. Let's take a look at the execution (we will use the same configuration as the example from earlier):

ansible-playbook -i inventory tasks.yml

It fails:

The reason for the failure can be seen in in the message: ...

Get Implementing Modern DevOps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.