Variables in Playbooks
Variables in Playbooks
Create a file variable.yaml in master terminal window and add the following text to
it.
---
- hosts: all
remote_user: test
tasks:
- name: Set variable 'name'
set_fact:
name: Test machine
- name: Print variable 'name'
debug:
msg: '{{ name }}'
Create a file setup_variable.yaml in master terminal window and add the following
text to it
---
- hosts: all
remote_user: test
tasks:
- name: Print OS and version
debug:
msg: '{{ ansible_distribution }} {{
ansible_distribution_version }}'
Create a file cli_variable.yaml in master terminal window and add the following text
to it
---
- hosts: all
remote_user: test
tasks:
- name: Print variable 'name'
debug:
msg: '{{ name }}'
In case we forgot to add the additional parameter to specify the variable, we would
have executed it as:
$ ansible-playbook -i client.test.org, cli_variables.yaml