[INFO] Créer le role

This commit is contained in:
pulsar89.5 2022-10-21 15:01:23 +02:00
parent f3cd65a0c7
commit 6f5443985a
6 changed files with 103 additions and 3 deletions

View File

@ -1,3 +1,59 @@
# role_modele
# role_etc_hosts
Modèle
Gérer le fichier /etc/hosts
## Variables
### etc_hosts_local
Liste de nom d'hôte attaché à 127.0.0.1.
<span style="text-decoration: underline">Valeur par défaut:</span> aucune
### etc_hosts_specifics
Liste de ligne à ajouter à `/etc/hosts`.
<span style="text-decoration: underline">Valeur par défaut:</span> aucune
---
## Exemple d'utilisation
### inventory.yml
```yaml
---
all:
hosts:
host1.ykn.local:
host2.ykn.local:
children:
dnsservers:
hosts:
dnsmasq1.ykn.local:
dnsmasq2.ykn.local:
```
### host_vars/host1.ykn.local.yml
```yaml
---
etc_hosts_local:
- www.ykn.fr
etc_hosts_specifics:
- 192.168.50.200 gitea.ykn.fr
```
### playbook.yml
```yaml
---
- hosts: 'all'
roles:
- name: etc_hosts
```

5
defaults/main.yml Normal file
View File

@ -0,0 +1,5 @@
---
# defaults file for etc_hosts
etc_hosts_local: []
etc_hosts_specifics: []

2
handlers/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
# handlers file for etc_hosts

View File

@ -1,7 +1,7 @@
galaxy_info:
namespace: ykn
author: pulsar89.5
description: Rôle modèle
description: Gérer le fichier /etc/hosts
license: GPL-3.0-or-later

9
tasks/main.yml Normal file
View File

@ -0,0 +1,9 @@
---
# tasks file for etc_hosts
- name: Déployer le fichier /etc/hosts
ansible.builtin.template:
mode: u=rw,g=r,o=r
src: hosts.j2
dest: /etc/hosts
become: true

28
templates/hosts.j2 Normal file
View File

@ -0,0 +1,28 @@
# {{ ansible_managed }}
{%- if inventory_hostname != inventory_hostname_short %}
{%- set host = inventory_hostname ~ ' ' ~ inventory_hostname_short %}
{%- else %}
{% set host = inventory_hostname_short %}
{%- endif %}
{%- if etc_hosts_local | length > 0 %}
{% set line = host ~ ' ' ~ (etc_hosts_local | join(' ')) %}
{%- else %}
{% set line = host %}
{%- endif +%}
127.0.0.1 {{ line }} localhost
# The following lines are desirable for IPv6 capable hosts
::1 {{ line }} localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
{% if etc_hosts_specifics | length > 0 %}
# The following lines are specified by instance configuration
{{ etc_hosts_specifics | join('\n') }}
{% endif %}