robertdebock/ansible-role-common

Allow to disable hosts rewrite and to use addresses from different interface then default_ipv4

Opened this issue · 0 comments

Proposed feature

Currently the role will always modify the hosts file. Allow to diable it on role level

    - role: robertdebock.common
      common_update_hosts: false

Currently hosts addresses are from ansible_default_ipv4

Allow to declare different interface to be used for the addresses:

    - role: robertdebock.common
      common_interface: ens6

Rationale

This is required when hosts have a dedicated management (ansible) interface as their default interface.
Example: This is most often the case when using molecule_vagrant with libvirt for instance and additional public network on a separate bridge device.

Clustered production systems most of the time have dedicated interfaces for cluster traffic.
Example: External services (dns/dhcp) might provide necessary address information. It would be required that hosts file is not written at all.

Additional context

Relevant sample snippet from molecule.yml :

driver:
  name: vagrant
  provider:
    name: libvirt
platforms:
  - name: db11${_TEST_DOMAIN:-.in.ndgit.com}
    box: almalinux/8
    memory: 8192
    cpus: 4
    interfaces:
      - network_name: public_network
        dev: "${_TEST_BRIDGE_DEV:-virbr0}"
        type: "bridge"
        mode: "bridge"
    groups:
      - pxc
...

Relevant sample snippet from ansible facts as an example:

{
    "ansible_default_ipv4": {
        "address": "192.168.122.198",
        "alias": "ens5",
        "broadcast": "192.168.122.255",
        "gateway": "192.168.122.1",
        "interface": "ens5",
        "macaddress": "52:54:00:c6:2d:38",
        "mtu": 1500,
        "netmask": "255.255.255.0",
        "network": "192.168.122.0",
        "type": "ether"
    },
    "ansible_ens5": {
        "ipv4": {
            "address": "192.168.122.198",
            "broadcast": "192.168.122.255",
            "netmask": "255.255.255.0",
            "network": "192.168.122.0"
        }
    },
    "ansible_ens6": {
        "ipv4": {
            "address": "192.168.5.10",
            "broadcast": "192.168.5.255",
            "netmask": "255.255.255.0",
            "network": "192.168.5.0"
        }
    }
}