Reworked script and playbook to include tags

This commit is contained in:
2025-08-07 13:31:07 -05:00
parent 19b63af8b2
commit e07d000435
2 changed files with 71 additions and 6 deletions

View File

@@ -100,14 +100,31 @@
linode_region: "{{ item.value.linode_region }}"
linode_type: "{{ item.value.linode_type }}"
linode_status: "{{ item.value.linode_status }}"
linode_tags: "{{ item.value.linode_tags }}"
is_debian: "{{ item.value.is_debian }}"
is_ubuntu: "{{ item.value.is_ubuntu }}"
is_k3s: "{{ item.value.is_k3s }}"
is_control_plane: "{{ item.value.is_control_plane }}"
is_worker_node: "{{ item.value.is_worker_node }}"
tag_string: "{{ item.value.tag_string }}"
loop: "{{ dynamic_inventory._meta.hostvars | dict2items }}"
when:
- dynamic_inventory is defined
- item.value.linode_status == "running"
- name: Display added hosts
- name: Display added hosts with tag information
ansible.builtin.debug:
msg: "Added {{ groups['discovered_linodes'] | default([]) | length }} running Linode hosts to inventory"
msg: |
Added {{ groups['discovered_linodes'] | default([]) | length }} running Linode hosts to inventory
Host details:
{% for host in groups['discovered_linodes'] | default([]) %}
- {{ host }} ({{ hostvars[host]['ansible_host'] }})
Tags: {{ hostvars[host]['linode_tags'] | join(', ') }}
K3s: {{ hostvars[host]['is_k3s'] }}
Control Plane: {{ hostvars[host]['is_control_plane'] }}
Worker: {{ hostvars[host]['is_worker_node'] }}
{% endfor %}
- name: Test connection to discovered Linode hosts
hosts: discovered_linodes
@@ -121,6 +138,45 @@
register: ping_result
ignore_errors: true
- name: Display connectivity status
- name: Display connectivity status with tag info
ansible.builtin.debug:
msg: "{{ inventory_hostname }} ({{ ansible_host }}): {{ 'REACHABLE' if ping_result is succeeded else 'UNREACHABLE' }}"
msg: |
{{ inventory_hostname }} ({{ ansible_host }}): {{ 'REACHABLE' if ping_result is succeeded else 'UNREACHABLE' }}
Tags: {{ linode_tags | join(', ') }}
Role: {{ 'Control Plane' if is_control_plane else 'Worker Node' if is_worker_node else 'Other' }}
# Example: Run tasks only on k3s control plane nodes
- name: Example - Control Plane specific tasks
hosts: discovered_linodes
gather_facts: false
vars:
ansible_user: root
tasks:
- name: Control plane specific task
ansible.builtin.debug:
msg: "This would run control plane specific commands on {{ inventory_hostname }}"
when: is_control_plane | bool
# Example: Run tasks only on k3s worker nodes
- name: Example - Worker Node specific tasks
hosts: discovered_linodes
gather_facts: false
vars:
ansible_user: root
tasks:
- name: Worker node specific task
ansible.builtin.debug:
msg: "This would run worker node specific commands on {{ inventory_hostname }}"
when: is_worker_node | bool
# Example: Run tasks on all k3s nodes (control plane + workers)
- name: Example - All K3s nodes
hosts: discovered_linodes
gather_facts: false
vars:
ansible_user: root
tasks:
- name: K3s cluster task
ansible.builtin.debug:
msg: "This would run on all k3s nodes: {{ inventory_hostname }}"
when: is_k3s | bool