Working with Ansible facts

Ansible is not only used to deploy and configure remote hosts. It can be used to gather all kinds of information and facts about them. The facts collection can take significant amount of time to collect everything from a busy system, but will provide a full view of the target machine.

The facts that are gathered can be used inside the playbook later, to design a task condition. For example, we used the when clause to limit the openssh installation to only CentOS-based systems:

when: Ansible_distribution == "CentOS"

You can enable/disable fact gathering in the Ansible plays by configuring gather_facts on the same level as hosts and tasks:

- hosts: centos-servers  gather_facts: yes  tasks:    <your tasks go here>

Another ...

Get Hands-On Enterprise Automation with Python. 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.