From e5f280987ae958001742a576381280cb70d5af9a Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Thu, 21 Aug 2025 11:39:43 -0400 Subject: [PATCH 1/2] Logic updates, CI fixes, formatting --- .gitea/workflows/ansible-test.yml | 2 +- galaxy.yml | 2 +- roles/etc_hosts/tasks/main.yml | 2 +- roles/hostname/tasks/main.yml | 2 +- roles/node_status/tasks/main.yml | 36 +++++++++++++++--------------- roles/resolv_conf/tasks/main.yml | 2 +- roles/snmpd_conf/handlers/main.yml | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.gitea/workflows/ansible-test.yml b/.gitea/workflows/ansible-test.yml index 601a3aa..9e87be0 100644 --- a/.gitea/workflows/ansible-test.yml +++ b/.gitea/workflows/ansible-test.yml @@ -9,7 +9,7 @@ jobs: Ansible-Development-Pipeline: strategy: matrix: - os: [ ansible-dev-centos9, ansible-dev-fedora39, ansible-dev-debian11, ansible-dev-debian12 ] + os: [ ansible-dev-centos, ansible-dev-fedora, ansible-dev-debian ] runs-on: ${{ matrix.os }} steps: diff --git a/galaxy.yml b/galaxy.yml index b9a5b5d..d6831b9 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: jchristianh name: baseos # The version of the collection. Must be compatible with semantic versioning -version: 1.0.34 +version: 1.0.35 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/roles/etc_hosts/tasks/main.yml b/roles/etc_hosts/tasks/main.yml index c296933..c45b3a9 100644 --- a/roles/etc_hosts/tasks/main.yml +++ b/roles/etc_hosts/tasks/main.yml @@ -3,7 +3,7 @@ ansible.builtin.set_fact: etc_hosts_etc_hosts_file: "{{ etc_hosts_etc_hosts_file }}.docker" when: - - ansible_virtualization_type | regex_search("docker|podman|container") + - ansible_virtualization_type is search("docker|podman|container") - name: Deploy {{ etc_hosts_etc_hosts_file }} diff --git a/roles/hostname/tasks/main.yml b/roles/hostname/tasks/main.yml index 9b85a65..48fc547 100644 --- a/roles/hostname/tasks/main.yml +++ b/roles/hostname/tasks/main.yml @@ -2,7 +2,7 @@ - name: Use hostname module to set hostname, or failback to command module when: - - not ansible_virtualization_type | regex_search("docker|podman|container") + - not ansible_virtualization_type is search("docker|podman|container") block: - name: Set hostname for host using hostname module ansible.builtin.hostname: diff --git a/roles/node_status/tasks/main.yml b/roles/node_status/tasks/main.yml index 2d14693..db601f3 100644 --- a/roles/node_status/tasks/main.yml +++ b/roles/node_status/tasks/main.yml @@ -1,33 +1,33 @@ --- - name: Update node status when not running in a container - when: not ansible_virtualization_type | regex_search("docker|podman|container") + when: not ansible_virtualization_type is search("docker|podman|container") block: - name: Create directory {{ node_status_dir }} ansible.builtin.file: - path : "{{ node_status_dir }}" - state : directory - mode : '0755' - become : false - run_once : true - delegate_to : "{{ node_status_host }}" + path: "{{ node_status_dir }}" + state: directory + mode: '0755' + become: false + run_once: true + delegate_to: "{{ node_status_host }}" - name: Capture system uptime ansible.builtin.command : uptime - register : r_node_status_uptime + register: r_node_status_uptime changed_when: false - name: Log node status ansible.builtin.lineinfile: - path : "{{ node_status_dir }}/{{ node_status_file }}" - state : present - regexp : "{{ inventory_hostname }}" - line : "{{ ansible_date_time.epoch }},,{{ inventory_hostname }},,{{ ansible_distribution }} {{ ansible_distribution_version }},,{{ r_node_status_uptime.stdout }}" - create : true - mode : '0644' - owner : "{{ node_status_user }}" - group : "{{ node_status_group }}" - delegate_to : "{{ node_status_host }}" - throttle : 1 + path: "{{ node_status_dir }}/{{ node_status_file }}" + state: present + regexp: "{{ inventory_hostname }}" + line: "{{ ansible_date_time.epoch }},,{{ inventory_hostname }},,{{ ansible_distribution }} {{ ansible_distribution_version }},,{{ r_node_status_uptime.stdout }}" + create: true + mode: '0644' + owner: "{{ node_status_user }}" + group: "{{ node_status_group }}" + delegate_to: "{{ node_status_host }}" + throttle: 1 diff --git a/roles/resolv_conf/tasks/main.yml b/roles/resolv_conf/tasks/main.yml index f00e59f..0b857af 100644 --- a/roles/resolv_conf/tasks/main.yml +++ b/roles/resolv_conf/tasks/main.yml @@ -3,7 +3,7 @@ ansible.builtin.set_fact: resolv_conf_resolv_conf_file: "{{ resolv_conf_resolv_conf_file }}.container" when: - - ansible_virtualization_type | regex_search("docker|podman|container") + - ansible_virtualization_type is search("docker|podman|container") - name: Deploy {{ resolv_conf_resolv_conf_file }} diff --git a/roles/snmpd_conf/handlers/main.yml b/roles/snmpd_conf/handlers/main.yml index 50ed6af..3da965f 100644 --- a/roles/snmpd_conf/handlers/main.yml +++ b/roles/snmpd_conf/handlers/main.yml @@ -4,4 +4,4 @@ name : snmpd state: restarted when: - - not ansible_virtualization_type | regex_search("docker|podman|container") + - not ansible_virtualization_type is search("docker|podman|container") From c1bf3ddefbf4760c9e7c6397877f2a617069934a Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Thu, 21 Aug 2025 11:44:10 -0400 Subject: [PATCH 2/2] Ansible-lint fixes --- meta/runtime.yml | 2 +- roles/motd/tasks/main.yml | 10 +++++----- roles/motd/templates/motd.j2 | 2 +- roles/node_status/tasks/main.yml | 6 ++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index ce6befd..1e85b01 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,2 +1,2 @@ --- -requires_ansible: ">=2.14.0" +requires_ansible: ">=2.15.0" diff --git a/roles/motd/tasks/main.yml b/roles/motd/tasks/main.yml index 8cee9ce..a6b46ac 100644 --- a/roles/motd/tasks/main.yml +++ b/roles/motd/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: Format uptime using Jinja ansible.builtin.set_fact: - uptime_formatted: | + motd_uptime_formatted: | {% if 'day' in motd_host_uptime %} {{ motd_host_uptime | regex_replace(motd_day_filter, motd_day_filter_repl) }} {% else %} @@ -11,10 +11,10 @@ - name: Update MOTD ansible.builtin.template: - src : templates/motd.j2 - dest : "{{ motd_motd_file }}" - mode : "0644" - changed_when : false + src: templates/motd.j2 + dest: "{{ motd_motd_file }}" + mode: "0644" + changed_when: false ... diff --git a/roles/motd/templates/motd.j2 b/roles/motd/templates/motd.j2 index e63fe88..b5a1f07 100644 --- a/roles/motd/templates/motd.j2 +++ b/roles/motd/templates/motd.j2 @@ -19,6 +19,6 @@ IP : {{ motd_host_ip }} CPU : {{ ansible_processor_vcpus }} x {{ ansible_processor[2] | regex_replace('\\s+', ' ') }} Memory : {{ "{0:0.2f}".format(ansible_memfree_mb/1024) }} GB free of {{ (ansible_memtotal_mb/1024)|round}} GB Platform : {{ ansible_distribution }} {{ ansible_distribution_version }} {{ ansible_kernel }} -Up : {{ uptime_formatted | trim }} +Up : {{ motd_uptime_formatted | trim }} diff --git a/roles/node_status/tasks/main.yml b/roles/node_status/tasks/main.yml index db601f3..1fd334b 100644 --- a/roles/node_status/tasks/main.yml +++ b/roles/node_status/tasks/main.yml @@ -11,19 +11,17 @@ run_once: true delegate_to: "{{ node_status_host }}" - - name: Capture system uptime ansible.builtin.command : uptime - register: r_node_status_uptime + register: node_status_sys_uptime changed_when: false - - name: Log node status ansible.builtin.lineinfile: path: "{{ node_status_dir }}/{{ node_status_file }}" state: present regexp: "{{ inventory_hostname }}" - line: "{{ ansible_date_time.epoch }},,{{ inventory_hostname }},,{{ ansible_distribution }} {{ ansible_distribution_version }},,{{ r_node_status_uptime.stdout }}" + line: "{{ ansible_date_time.epoch }},,{{ inventory_hostname }},,{{ ansible_distribution }} {{ ansible_distribution_version }},,{{ node_status_sys_uptime.stdout }}" create: true mode: '0644' owner: "{{ node_status_user }}"