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 comment

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency
Exit mobile version
%%footer%%