fix: hostname and domain setup
This commit is contained in:
parent
a5e773a007
commit
55ba4275ee
@ -9,3 +9,8 @@ system_packages__default: []
|
||||
system_accounts: "{{ vars | dict2items | selectattr('key', 'match', '^system_accounts__.*') | map(attribute='value') | list | flatten | unique }}"
|
||||
system_packages: "{{ vars | dict2items | selectattr('key', 'match', '^system_packages__.*') | map(attribute='value') | list | flatten | unique }}"
|
||||
|
||||
# system_hostname: "{{ ansible_hostname }}"
|
||||
system_hostname: "{{ inventory_hostname | split('.') | first }}"
|
||||
system_domain: "{{ (inventory_hostname | split('.'))[1:] | join('.') }}"
|
||||
# system_domain: "lan.test"
|
||||
system_fqdn: "{{ system_hostname }}.{{ system_domain }}"
|
||||
@ -8,7 +8,11 @@
|
||||
role_config:
|
||||
system_accounts: "{{ system_accounts }}"
|
||||
system_packages: "{{ system_packages }}"
|
||||
system_hostname: "{{ system_hostname }}"
|
||||
system_domain: "{{ system_domain }}"
|
||||
system_fqdn: "{{ system_fqdn }}"
|
||||
tasks:
|
||||
- "Configure system hostname, domain and fqdn"
|
||||
- Ensure system security groups are present
|
||||
- Create system users from system_accounts
|
||||
- Ensure ssh keys are correctly deployed
|
||||
@ -18,6 +22,23 @@
|
||||
tags:
|
||||
- config_show
|
||||
|
||||
# Configure system fqdn
|
||||
# ==========================
|
||||
- name: Configure system hostname in /etc/hosts
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/hosts
|
||||
regexp: '^127\.0\.1\.1 '
|
||||
line: '127.0.1.1 {{ system_fqdn }} {{ system_hostname }}'
|
||||
state: present
|
||||
register: machine_name_changed
|
||||
|
||||
- name: "Apply system hostname (changed={{ machine_name_changed.changed }})"
|
||||
ansible.builtin.shell:
|
||||
cmd: "test '{{ ansible_check_mode|lower }}' == true || hostnamectl set-hostname {{ system_fqdn }}"
|
||||
when: machine_name_changed.changed
|
||||
changed_when: true
|
||||
check_mode: false
|
||||
|
||||
|
||||
# Configure groups and users
|
||||
# ==========================
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user