Giter Club home page Giter Club logo

ansible-role-hosts's Introduction

ansible-role-hosts

GitHub GitHub last commit GitHub issues Molecule

Ansible role for configuring the /etc/hosts file.

Supported Platforms

OS Family Distribution Latest Supported Version(s) Comment
Alpine Alpine ✔️ 3.11, 3.12, 3.13
Archlinux Archlinux ✔️ -
Manjaro ✔️ -
Debian Debian ✔️ 10, 11
Ubuntu ✔️ 18.04, 20.04
RedHat Almalinux ✔️ 8
Amazonlinux - not tested, image not working
Centos ✔️ 7, 8
Fedora ✔️ 33, 34, Rawhide
Oraclelinux ✔️ 7, 8
Suse OpenSuse Leap ✔️ 15.1, 15.2, 15.3
Tumbleweed ✔️ -

Requirements

Ansible 2.9 or higher.

Variables

Variables and defaults for this role.

defaults/main.yml

# The role is disabled by default, so you do not get in trouble.
# Checked in tasks/main.yml which includes tasks.yml if enabled.
hosts_role_enabled: false

# Backup the hosts file when applying template
hosts_backup: true

# Set domain for FQDN in hosts file.
# Only overwrite this if you want to force the domain manually.
# Normally ansible_domain should be set if you have a sane network configuration.
hosts_domain: "{{ (ansible_domain | length > 0) | ternary(ansible_domain, '') }}"

# Determine how the targeted host(s) is added to /etc/hosts
# hosts_ip_all:
#   true  = generates entries for all IPs in ansible_all_ipvX_addresses
#           with ansible_fqdn and ansible_hostname
#   false = generates single entry for value of key "address"
#           with ansible_fqdn and ansible_hostname dependant on static setting
hosts_ip_all: false
# hosts_ip_static:
#   true  = use address defined in key "address"
#   false = use 127.0.1.1 if IP obtained via dhcp.
#           If IP is not obtained by dhcp the value of key "address" is used.
hosts_ip_static: false
# hosts_ip_static:
#   IP address to use, when "hosts_ip_all: false", and
#   "hosts_ip_static: true" or "static: false" and IP not obtained via dhcp
#   If "static: false" and IP was obtained via dhcp then 127.0.1.1 is used
hosts_ip_address: "{{ ansible_default_ipv4.address }}"

# Additional entries in the hosts file
# hosts_entries:
#   - name: test.blabla.tld
#     aliases:
#       - test
#       - sys01.blabla.tld
#     ip: 192.168.08.15
#   - name: test6.blabla.tld
#     aliases:
#       - test6
#     ip: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
hosts_entries: []

Dependencies

None.

Example Playbooks

Here are some example configurations.

Systems with one interface and single IP address

---
# role: ansible-role-hosts
# file: site.yml

- hosts: all
  become: true
  gather_facts: true
  vars:
    hosts_role_enabled: true
  roles:
    - role: ansible-role-hosts

Force static IP in /etc/hosts even if obtained by dhcp

---
# role: ansible-role-hosts
# file: site.yml

- hosts: all
  become: true
  gather_facts: true
  vars:
    hosts_role_enabled: true
    hosts_ip_static: true
  roles:
    - role: ansible-role-hosts

Generate /etc/hosts with all IPv4 addresses of the host

---
# role: ansible-role-hosts
# file: site.yml

- hosts: all
  become: true
  gather_facts: true
  vars:
    hosts_role_enabled: true
    hosts_ip_all: true
  roles:
    - role: ansible-role-hosts

License and Author

Licensed under MIT License. See LICENSE file in repository.

ansible-role-hosts's People

Contributors

jomrr avatar

Watchers

 avatar  avatar

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.