Example 14
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
playbook.yml
- name: Example playbook
hosts: centos1
gather_facts: false
tasks:
- name: Set a custom fact
set_fact:
custom_fact: This is a custom fact
- name: Print the custom fact
debug:
msg: "{{ custom_fact }}"
Tip
Another way to manipulate facts in runtime is the set_fact
module. This allows the user to set facts in a dynamic manner.
Execute the following command
ansible-playbook playbook.yml