fix: simplifie code
This commit is contained in:
parent
40a500a3eb
commit
441a7b8e24
@ -2,3 +2,9 @@
|
|||||||
nsf_mount__default: []
|
nsf_mount__default: []
|
||||||
nfs_mounts: "{{ vars | dict2items | selectattr('key', 'match', '^nfs_mounts__.*') | map(attribute='value') | list | flatten | unique }}"
|
nfs_mounts: "{{ vars | dict2items | selectattr('key', 'match', '^nfs_mounts__.*') | map(attribute='value') | list | flatten | unique }}"
|
||||||
|
|
||||||
|
nfs_mounts_install_pkg: >-
|
||||||
|
{{
|
||||||
|
((nfs_mounts|d(false, true)) != false)
|
||||||
|
| ternary(true, false)
|
||||||
|
}}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
role_config:
|
role_config:
|
||||||
nfs_mounts: "{{ nfs_mounts }}"
|
nfs_mounts: "{{ nfs_mounts }}"
|
||||||
tasks:
|
tasks:
|
||||||
- Ensure nfs-client packages are installed
|
- "Ensure nfs-client packages are installed: {{ nfs_mounts_install_pkg }}"
|
||||||
- "Create {{ nfs_mounts | length }} mounts directories"
|
- "Create {{ nfs_mounts | length }} mounts directories"
|
||||||
- "Ensure {{ nfs_mounts | length }} mounts are in fstab"
|
- "Ensure {{ nfs_mounts | length }} mounts are in fstab"
|
||||||
tags:
|
tags:
|
||||||
@ -19,6 +19,7 @@
|
|||||||
package:
|
package:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
state: present
|
state: present
|
||||||
|
when: nfs_mounts_install_pkg
|
||||||
with_items:
|
with_items:
|
||||||
- nfs-common
|
- nfs-common
|
||||||
|
|
||||||
|
|||||||
@ -13,4 +13,6 @@ system_packages: "{{ vars | dict2items | selectattr('key', 'match', '^system_pac
|
|||||||
system_hostname: "{{ inventory_hostname | split('.') | first }}"
|
system_hostname: "{{ inventory_hostname | split('.') | first }}"
|
||||||
system_domain: "{{ (inventory_hostname | split('.'))[1:] | join('.') }}"
|
system_domain: "{{ (inventory_hostname | split('.'))[1:] | join('.') }}"
|
||||||
# system_domain: "lan.test"
|
# system_domain: "lan.test"
|
||||||
system_fqdn: "{{ system_hostname }}.{{ system_domain }}"
|
system_fqdn: "{{ system_hostname }}.{{ system_domain }}"
|
||||||
|
system_real_fqdn:
|
||||||
|
system_real_address:
|
||||||
|
|||||||
@ -27,10 +27,21 @@
|
|||||||
- name: Configure system hostname in /etc/hosts
|
- name: Configure system hostname in /etc/hosts
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/hosts
|
path: /etc/hosts
|
||||||
regexp: '^127\.0\.1\.1 '
|
regexp: "{{ item.regexp }}"
|
||||||
line: '127.0.1.1 {{ system_fqdn }} {{ system_hostname }}'
|
line: "{{ item.line }}"
|
||||||
state: present
|
state: present
|
||||||
register: machine_name_changed
|
register: machine_name_changed
|
||||||
|
loop:
|
||||||
|
- regexp: '^127\.0\.1\.1(\t\s)*'
|
||||||
|
line: '127.0.1.1 {{ system_fqdn }} {{ system_hostname }}'
|
||||||
|
state: present
|
||||||
|
- regexp: '^{{ system_real_address }}(\t\s)*'
|
||||||
|
line: "{{ system_real_address }} {{ system_real_fqdn }} {{ system_real_fqdn|split('.')|first }}"
|
||||||
|
state: >-
|
||||||
|
{{
|
||||||
|
( system_real_address|d('') != '' )
|
||||||
|
| ternary('present', 'absent')
|
||||||
|
}}
|
||||||
|
|
||||||
- name: "Apply system hostname (changed={{ machine_name_changed.changed }})"
|
- name: "Apply system hostname (changed={{ machine_name_changed.changed }})"
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
@ -52,7 +63,7 @@
|
|||||||
- wheel
|
- wheel
|
||||||
- sudo
|
- sudo
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "Install package: {{ item }}"
|
label: "Ensure group: {{ item }}"
|
||||||
|
|
||||||
- name: Create users
|
- name: Create users
|
||||||
user:
|
user:
|
||||||
@ -93,19 +104,28 @@
|
|||||||
# Configure package manager
|
# Configure package manager
|
||||||
# ==========================
|
# ==========================
|
||||||
|
|
||||||
- name: Configure APT preferences
|
#- name: Configure APT preferences
|
||||||
|
# copy:
|
||||||
|
# dest: "/etc/apt/apt.conf.d/{{ item.name }}"
|
||||||
|
# content: "{{ item.content }}"
|
||||||
|
# loop:
|
||||||
|
# - name: 01-norecommend
|
||||||
|
# content: |
|
||||||
|
# APT::Install-Recommends "{{ system_packages_norecommend | bool | ternary(0, 1) }}";
|
||||||
|
# - name: 02-suggest
|
||||||
|
# content: |
|
||||||
|
# APT::Install-Suggests "{{ system_packages_nosuggest | bool | ternary(0, 1) }}";
|
||||||
|
# loop_control:
|
||||||
|
# label: "Ensure APT preference: {{ item.content }}"
|
||||||
|
|
||||||
|
- name: Ensure apt only install minimal packages
|
||||||
copy:
|
copy:
|
||||||
dest: "/etc/apt/apt.conf.d/{{ item.name }}"
|
dest: /etc/apt/apt.conf.d/90_install_mode
|
||||||
content: "{{ item.content }}"
|
content: |
|
||||||
loop:
|
# Ansible managed
|
||||||
- name: 01-norecommend
|
APT::Install-Recommends "{{ system_packages_norecommend | bool | ternary(1, 0) }}";
|
||||||
content: |
|
APT::Install-Suggests "{{ system_packages_nosuggest | bool | ternary(1, 0) }}";
|
||||||
APT::Install-Recommends "{{ system_packages_norecommend | bool | ternary(0, 1) }}";
|
|
||||||
- name: 02-suggest
|
|
||||||
content: |
|
|
||||||
APT::Install-Suggests "{{ system_packages_nosuggest | bool | ternary(0, 1) }}";
|
|
||||||
loop_control:
|
|
||||||
label: "Ensure APT preference: {{ item.content }}"
|
|
||||||
|
|
||||||
- name: Install base tools
|
- name: Install base tools
|
||||||
package:
|
package:
|
||||||
|
|||||||
@ -6,3 +6,8 @@ disks_lv__default: []
|
|||||||
disks_vg: "{{ vars | dict2items | selectattr('key', 'match', '^disks_vg__.*') | map(attribute='value') | list | flatten | unique }}"
|
disks_vg: "{{ vars | dict2items | selectattr('key', 'match', '^disks_vg__.*') | map(attribute='value') | list | flatten | unique }}"
|
||||||
disks_lv: "{{ vars | dict2items | selectattr('key', 'match', '^disks_lv__.*') | map(attribute='value') | list | flatten | unique }}"
|
disks_lv: "{{ vars | dict2items | selectattr('key', 'match', '^disks_lv__.*') | map(attribute='value') | list | flatten | unique }}"
|
||||||
|
|
||||||
|
disks_install_lvm_pkg: >-
|
||||||
|
{{
|
||||||
|
((pv|d(vg|d(lv|d(false, true)))) != false)
|
||||||
|
| ternary(true, false)
|
||||||
|
}}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
disks_vg: "{{ disks_vg }}"
|
disks_vg: "{{ disks_vg }}"
|
||||||
disks_lv: "{{ disks_lv }}"
|
disks_lv: "{{ disks_lv }}"
|
||||||
tasks:
|
tasks:
|
||||||
- Ensure lvm packages are installed
|
- "Ensure lvm packages are installed: {{ disks_install_lvm_pkg }}"
|
||||||
- Copy lvm detector script
|
- Copy lvm detector script
|
||||||
- "Ensure all PVs and {{ disks_vg | length }} VGs are correctly setup"
|
- "Ensure all PVs and {{ disks_vg | length }} VGs are correctly setup"
|
||||||
- "Ensure all {{ disks_lv | length }} LVs are in correct state"
|
- "Ensure all {{ disks_lv | length }} LVs are in correct state"
|
||||||
@ -24,6 +24,7 @@
|
|||||||
- lvm2
|
- lvm2
|
||||||
- parted
|
- parted
|
||||||
state: present
|
state: present
|
||||||
|
when: disks_install_lvm_pkg
|
||||||
|
|
||||||
# This should be the way, as it is not possible with cloudinit ...
|
# This should be the way, as it is not possible with cloudinit ...
|
||||||
- name: Copy lvm volume detector script
|
- name: Copy lvm volume detector script
|
||||||
@ -31,6 +32,7 @@
|
|||||||
src: setup_lvm_devices.sh
|
src: setup_lvm_devices.sh
|
||||||
dest: /usr/local/sbin/setup_lvm_devices.sh
|
dest: /usr/local/sbin/setup_lvm_devices.sh
|
||||||
mode: "755"
|
mode: "755"
|
||||||
|
when: disks_install_lvm_pkg
|
||||||
|
|
||||||
- name: Ensure presence of all VG
|
- name: Ensure presence of all VG
|
||||||
community.general.lvg:
|
community.general.lvg:
|
||||||
|
|||||||
@ -15,7 +15,7 @@ systemd_networkd_cleanup: false
|
|||||||
systemd_networkd_cleanup_patterns: []
|
systemd_networkd_cleanup_patterns: []
|
||||||
systemd_networkd_cleanup_patterns_use_regex: false
|
systemd_networkd_cleanup_patterns_use_regex: false
|
||||||
|
|
||||||
systemd_networkd_manage_nsswitch_config: true
|
systemd_networkd_manage_nsswitch_config: false
|
||||||
systemd_networkd_nsswitch_passwd: files systemd
|
systemd_networkd_nsswitch_passwd: files systemd
|
||||||
systemd_networkd_nsswitch_group: files systemd
|
systemd_networkd_nsswitch_group: files systemd
|
||||||
systemd_networkd_nsswitch_shadow: files systemd
|
systemd_networkd_nsswitch_shadow: files systemd
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user