GithubHelp home page GithubHelp logo

robertdebock / ansible-role-common Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 3.0 260 KB

The purpose of this role is to configure common things on your system.

Home Page: https://robertdebock.nl/

License: Apache License 2.0

Jinja 100.00%
common hosts hostname server system ansible molecule tox playbook

ansible-role-common's Introduction

The purpose of this role is to configure common things on your system.

GitHub GitLab Downloads Version
github gitlab downloads Version

This example is taken from molecule/default/converge.yml and is tested on each push, pull request and release.

---
- name: Converge
  hosts: all
  become: true
  gather_facts: true

  roles:
    - role: robertdebock.common

The machine needs to be prepared. In CI this is done using molecule/default/prepare.yml:

---
- name: Prepare
  hosts: all
  gather_facts: false
  become: true

  roles:
    - role: robertdebock.bootstrap

Also see a full explanation and example on how to use these roles.

The default values for the variables are set in defaults/main.yml:

---
# defaults file for common

# The selected hostname.
common_hostname: "{{ inventory_hostname }}"

# A list of nameservers to configure.
# common_nameservers:
#   - 1.1.1.1
#   - 1.0.0.1

# Fill /etc/hosts with all hosts in the play.
common_hosts: "{{ groups.all }}"

# Do you want to reboot on a hostname change?
common_reboot: true

The following roles are used to prepare a system. You can prepare your system in another way.

Requirement GitHub GitLab
robertdebock.bootstrap Build Status GitHub Build Status GitLab

This role is a part of many compatible roles. Have a look at the documentation of these roles for further information.

Here is an overview of related roles: dependencies

This role has been tested on these container images:

container tags
Alpine all
Amazon Candidate
EL 8, 9
Debian all
Fedora all
opensuse all
Ubuntu all

The minimum version of Ansible required is 2.12, tests have been done to:

  • The previous version.
  • The current version.
  • The development version.

If you find issues, please register them in GitHub.

Apache-2.0.

robertdebock

Please consider sponsoring me.

ansible-role-common's People

Contributors

dmrub avatar robert-de-bock avatar robertdebock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tombull dmrub ndgit

ansible-role-common's Issues

File hosts.j2 missing

Hi

Looks like the collection is missing the template of the hosts file:

TASK [robertdebock.roles.common : fill /etc/hosts] *****************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
fatal: [foo1]: FAILED! => changed=false
  msg: |-
    Could not find or access 'hosts.j2'
    Searched in:
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/templates/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/tasks/templates/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/tasks/hosts.j2
            /Users/tdeutsch/git/k8s-server/ansible/plays/templates/hosts.j2
            /Users/tdeutsch/git/k8s-server/ansible/plays/hosts.j2 on the Ansible Controller.
    If you are using a module and expect the file to exist on the remote, see the remote_src option
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
fatal: [foo2]: FAILED! => changed=false
  msg: |-
    Could not find or access 'hosts.j2'
    Searched in:
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/templates/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/tasks/templates/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/tasks/hosts.j2
            /Users/tdeutsch/git/k8s-server/ansible/plays/templates/hosts.j2
            /Users/tdeutsch/git/k8s-server/ansible/plays/hosts.j2 on the Ansible Controller.
    If you are using a module and expect the file to exist on the remote, see the remote_src option
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
fatal: [foo3]: FAILED! => changed=false
  msg: |-
    Could not find or access 'hosts.j2'
    Searched in:
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/templates/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/tasks/templates/hosts.j2
            /Users/tdeutsch/.ansible/collections/ansible_collections/robertdebock/roles/roles/common/tasks/hosts.j2
            /Users/tdeutsch/git/k8s-server/ansible/plays/templates/hosts.j2
            /Users/tdeutsch/git/k8s-server/ansible/plays/hosts.j2 on the Ansible Controller.
    If you are using a module and expect the file to exist on the remote, see the remote_src option

I downloaded the collection today.

Br
Thomas

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

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"
        }
    }
}

'update_reboot' is undefined

Describe the bug

fatal: [HOST]: FAILED! => {"msg": "The conditional check 'update_reboot' failed. The error was: error while evaluating conditional (update_reboot): 'update_reboot' is undefined\n\nThe error appears to have been in 'roles/robertdebock.common/handlers/main.yml': line 7, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: reboot for hostname\n  ^ here\n"}

Copy-pasted from the update role, needs a fix.

To Reproduce
Steps to reproduce the behavior:

  1. Run this role.
  2. See error.

Run common role with empty common_nameservers variable

Proposed feature

I would like to be able to run common role without changing nameservers, but it is currently not possible because I get the following error message when I set the variable common_nameservers to an empty array:
Fatal: [asr-vm-rundeck]: FAILED! => {"assertion": "common_nameservers | length > 0", "changed": false, "evaluated_to": false, "msg": "Assertion failed"}

Rationale

Why is this feature required?

Not in all cases it is desired to replace name servers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.