DevOps Classroomnotes 31/May/2023

Ansible contd

Facts

  • ansible collects information about the node on which it is executing by the help of module called as setup
  • Ansible playbook by default collects information about nodes where it is executing, we can use this with the help of variables
  • Collecting information can be disabled as well
---
- name: do something
  hosts: all
  gather_facts: no
  ...
  ...

  • In the playbook the facts will be collected and will be available in a special variables ansible_facts
  • Consider the below playbook
---
- name: exploring facts
  become: no
  hosts: all
  tasks:
    - name: print os details
      ansible.builtin.debug:
        msg: "family: {{ ansible_facts['os_family'] }} distribution: {{ ansible_facts['distribution'] }}"

  • The statement ansible_facts['os_family'] represents accessing os family from the facts collected
  • From facts the variables can be accessed with full names ansible_default_ipv4 or ansible_facts['default_ipv4']
---
- name: exploring facts
  become: no
  hosts: all
  tasks:
    - name: print os details
      ansible.builtin.debug:
        var: ansible_default_ipv4
    - name: same info
      ansible.builtin.debug:
        var: ansible_facts['default_ipv4']
  • Lets apply conditionals to ansible playbook Refer Here
  • Refer Here for the changeset and focus on combined.json

Explore

  • Explore the verbosity levels of execution i.e -v, -vv , -vvv ..
  • Write an ansible adhoc command to install git on node1
sudo apt install git
sudo yum install git

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Wordpress Development Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube