Merge pull request 'BaseOS v1.0.21' (#6) from testing into main

Reviewed-on: #6
This commit is contained in:
Chris Hammer 2024-02-28 20:05:59 -05:00
commit d752b8064b
4 changed files with 52 additions and 8 deletions

View File

@ -8,7 +8,7 @@ namespace: jchristianh
name: baseos
# The version of the collection. Must be compatible with semantic versioning
version: 1.0.20
version: 1.0.21
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md

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: "{{ inventory_hostname }}"
notify:
- "Restart_syslog_{{ ansible_distribution | lower }}_{{ ansible_distribution_major_version }}"
- name: Use hostname module to set hostname, or failback to command module
block:
- name: Set hostname for host using hostname module
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:
resolv_conf_resolv_conf_file: "{{ resolv_conf_resolv_conf_file }}.docker"
resolv_conf_resolv_conf_file: "{{ resolv_conf_resolv_conf_file }}.container"
when:
- ansible_virtualization_type | regex_search("docker|podman|container")