From 74f5fdfedd9c1c671cbb1caef969cfce621a058a Mon Sep 17 00:00:00 2001 From: freezed <git-expect-noreply@freezed.me> Date: Sun, 1 Jan 2023 01:40:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20SYSTEM=20Improve=20hosts=20&=20h?= =?UTF-8?q?ostname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/system_cfg/main.yml | 14 +++++--- tasks/system_cfg/shell.yml | 8 ----- tasks/system_cfg/templates/etc-hosts.j2 | 36 +++++++++++++++++++ .../system_cfg/templates/ssh-config_backup.j2 | 14 ++++++++ 4 files changed, 59 insertions(+), 13 deletions(-) delete mode 100644 tasks/system_cfg/shell.yml create mode 100644 tasks/system_cfg/templates/etc-hosts.j2 create mode 100644 tasks/system_cfg/templates/ssh-config_backup.j2 diff --git a/tasks/system_cfg/main.yml b/tasks/system_cfg/main.yml index 8edec4c..373ab9e 100644 --- a/tasks/system_cfg/main.yml +++ b/tasks/system_cfg/main.yml @@ -8,13 +8,17 @@ - name: HOSTNAME | setup ansible.builtin.hostname: - name: "{{ ansible_hostname }}" + name: "{{ inventory_hostname }}" - - name: IMPORT_TASKS | firewall - ansible.builtin.import_tasks: firewall.yml + - name: HOSTS | setup + ansible.builtin.template: + dest: "/etc/hosts" + src: templates/etc-hosts.j2 + backup: true + mode: 0640 - - name: IMPORT_TASKS | font - ansible.builtin.import_tasks: font.yml + - name: ANSIBLE | re-gather facts + ansible.builtin.setup: - name: IMPORT_TASKS | ldp ansible.builtin.import_tasks: ldp.yml diff --git a/tasks/system_cfg/shell.yml b/tasks/system_cfg/shell.yml deleted file mode 100644 index 4424861..0000000 --- a/tasks/system_cfg/shell.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- - -- name: "SHELL | set zsh for {{ my_user }}" - when: inventory_hostname in groups.station - ansible.builtin.user: - name: "{{ my_user }}" - shell: /bin/zsh - state: present diff --git a/tasks/system_cfg/templates/etc-hosts.j2 b/tasks/system_cfg/templates/etc-hosts.j2 new file mode 100644 index 0000000..17ee16d --- /dev/null +++ b/tasks/system_cfg/templates/etc-hosts.j2 @@ -0,0 +1,36 @@ +#jinja2:lstrip_blocks: True +# ############################################# # +# This file is managed by Ansible # +# Manual edition will be overridden # +# https://lab.frogg.it/freezed/ansible-debian # +# ############################################# # + +127.0.0.1 localhost +127.0.1.1 {{ inventory_fqdn }} {{ inventory_hostname }} +{{ ansible_host }} {{ inventory_fqdn }} {{ inventory_hostname }} + +{% if inventory_hostname in groups['station'] or inventory_hostname in groups['backup'] %} +# WAN + {% for host in groups['production'] %} +{{ hostvars[host]['ansible_host'] }} {{ hostvars[host]['inventory_fqdn'] }} {{ host }} + {% endfor %} +{% endif %} + +{% if inventory_hostname in groups['station'] or inventory_hostname in groups['production'] %} +# BKP + {% for host in groups['backup'] %} +{{ hostvars[host]['ansible_host'] }} {{ hostvars[host]['inventory_fqdn'] }} {{ host }} + {% endfor %} +{% endif %} + +{% if inventory_hostname in groups['station'] %} +# DEV + {% for host in groups['devel'] %} +{{ hostvars[host]['ansible_host'] }} {{ hostvars[host]['inventory_fqdn'] }} {{ host }} + {% endfor %} + +# LOCAL + {% for host in groups['station'] %} +{{ hostvars[host]['ansible_host'] }} {{ hostvars[host]['inventory_fqdn'] }} {{ host }} + {% endfor %} +{% endif %} diff --git a/tasks/system_cfg/templates/ssh-config_backup.j2 b/tasks/system_cfg/templates/ssh-config_backup.j2 new file mode 100644 index 0000000..8250385 --- /dev/null +++ b/tasks/system_cfg/templates/ssh-config_backup.j2 @@ -0,0 +1,14 @@ +#jinja2:lstrip_blocks: True +# ############################################# # +# This file is managed by Ansible # +# Manual edition will be overridden # +# https://lab.frogg.it/freezed/ansible-debian # +# ############################################# # + +{% for host in groups['production'] %} +Host {{ host }} + User {{ hostvars[host]['my_user'] }} + Hostname {{ hostvars[host]['ansible_host'] }} + Port {{ hostvars[host]['ansible_port'] }} + +{% endfor %} -- GitLab