Updates for better compatibility
All checks were successful
continuous-integration/drone/push Build is passing
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-centos9) (push) Successful in 20s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-debian11) (push) Successful in 12s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-debian12) (push) Successful in 12s
Ansible Code Pipeline / Ansible-Development-Pipeline (ansible-dev-fedora39) (push) Successful in 14s

This commit is contained in:
Chris Hammer 2024-02-28 20:01:57 -05:00
parent e5910f073d
commit a834789df5
3 changed files with 51 additions and 7 deletions

View File

@ -0,0 +1,13 @@
---
hostname_project_author : Chris Hammer
hostname_project_email : chris@thezengarden.net
hostname_project_repo : https://github.com/jchristianh-ansible-collections/baseos
hostname_template_header : The Zen Garden
hostname_hostname_file : /etc/hostname
hostname_hostname_version : 1.0.0
hostname_hostname_revision : 240228
...

View File

@ -1,9 +1,40 @@
--- ---
- name: Set hostname for host
ansible.builtin.hostname: - name: Use hostname module to set hostname, or failback to command module
name: "{{ inventory_hostname }}" block:
notify: - name: Set hostname for host using hostname module
- "Restart_syslog_{{ ansible_distribution | lower }}_{{ ansible_distribution_major_version }}" ansible.builtin.hostname:
name: "{{ inventory_hostname }}"
notify:
- "Restart_syslog_{{ ansible_distribution | lower }}_{{ ansible_distribution_major_version }}"
rescue:
- name: Ensure hostname package is present
ansible.builtin.package:
name: hostname
state: present
- name: Set hostname file if running in container
ansible.builtin.set_fact:
hostname_hostname_file: "{{ hostname_hostname_file }}.container"
when:
- ansible_virtualization_type | regex_search("docker|podman|container")
- name: Add entry into hostname file
ansible.builtin.lineinfile:
path: "{{ hostname_hostname_file }}"
line: "{{ inventory_hostname }}"
state: present
create: true
mode: '0644'
- name: Update hostname from /etc/hostname
ansible.builtin.command:
cmd: "hostname -F {{ hostname_hostname_file }}"
notify:
- "Restart_syslog_{{ ansible_distribution | lower }}_{{ ansible_distribution_major_version }}"
when:
- not ansible_virtualization_type | regex_search("docker|podman|container")
... ...

View File

@ -1,7 +1,7 @@
--- ---
- name: Set resolv_conf_file if running in container - name: Set resolv.conf if running in container
ansible.builtin.set_fact: ansible.builtin.set_fact:
resolv_conf_resolv_conf_file: "{{ resolv_conf_resolv_conf_file }}.docker" resolv_conf_resolv_conf_file: "{{ resolv_conf_resolv_conf_file }}.container"
when: when:
- ansible_virtualization_type | regex_search("docker|podman|container") - ansible_virtualization_type | regex_search("docker|podman|container")