Skip to content

Common


This role is designed to be included in all playbooks as it offers features to dynamically setup the ansible environment.

Role Details

Item Value Description
Dependent Roles None
Gate Variables common_gather_facts Optional, default not defned which is the same as false, gather Ansible facts.
Idempotent Yes* All except when configuring dns.
Stats Available Not Yet Available under yaml path nfc_common.
Tags Nil If you specify tags for running your playbooks, if this roll is included all tasks will still run as if tag always was specified.
stats_hosts used to collect hosts stats. Note: To only collect the host(s) information you must also specify --skip-tags alwaysas this role will run ALL tasks. This is by design.

when adding this role to a playbook, ensure that gather_facts is set to no for the play. this role gathers the facts for you. i.e.

Playbook example

---
- hosts: "{{ groups.servers }}"
  gather_facts: no

  roles:

    - name: Common tasks
      role: nfc_common
      vars:
        common_gather_facts: true

# Additional roles or playbook_include below this line

Tip

If the variable common_gather_facts is not set to true, by default facts will not be gathered.

Features

The following feaatures are available for this role:

  • setting the hostname

  • DNS. Installs resolvconf and configures.

  • Host details collection for use with automations

  • updating hosts file

  • setting up network interfaces with either static or dynamic settings

  • installing software via aptitude

  • setting common variables for use

APT

to setup and use apt to either add a repository or install/remove software the following variable template is required

aptSigningKeys:
      - name: docker
        url: https://download.docker.com/linux/debian/gpg
        save_directory: /usr/share/keyrings
        file_extension: asc # file extension to save key as, if `.gpg` specify `.gpg` otherwise specify `.asc` by default

    aptRepositories:
      - name: kubernetes # repo name
        repo: deb [signed-by=/usr/share/keyrings/kubernetes.gpg] https://apt.kubernetes.io/ kubernetes-xenial main # repo file entry

    aptInstall:
      - name: containerd.io # name of apt package
        version: "{{ ContainerDioVersion }}" # optional: if specified, will install that version and lock it from auto update.

Common Variables

This role sets the following variables:

  • host_vars[{hostname}].dynamic_processor_architecture to the processor architecture, either amd64, arm64 or x86.

Stat Collection

As part of the initial run-once tasks the role collects the details of the host(s) within the inventory. The information gathered is intended to aid in automations with all host information available under the hosts object.

stat output example

{
  "hosts": {
    "{inventory_hostname}": {
      "manufacturer": "",
      "model": "",
      "serial_number": "",
      "uuid": ""
    },
    "next_host": {} // etc
  }
}

AWX / Ansible Automation Platform

As this role is designed to work with AWX/Ansible Automation Platform the stats are not per_host as this is not supported in AWX.

todo

  • iterate through kubernetes hosts hostvars['hostname'].{whatever ipaddress is} to update each nodes hosts file. ref https://stackoverflow.com/a/40029455

  • add ability to set timezone

About:

This page forms part of our Project Common Ansible Role.

Page Metadata
Version: ToDo: place files short git commit here
Date Created: 2023-10-25
Date Edited: 2023-12-09

Contribution:

Would You like to contribute to our Common Ansible Role project? You can assist in the following ways:

 

ToDo: Add the page list of contributors