81398e847e
- Updated all tasks to use fully qualified module names (e.g., ansible.builtin.shell, ansible.builtin.copy) for clarity and to avoid ambiguity. - Replaced deprecated 'yum' module with 'dnf' for package management on RedHat-based systems. - Improved formatting and consistency in task definitions, including the use of double quotes for strings and consistent indentation. - Removed unnecessary comments and whitespace to enhance readability. - Ensured that conditions and loops are consistently formatted across all tasks.
62 lines
1.8 KiB
YAML
62 lines
1.8 KiB
YAML
---
|
|
- name: (systemd-services.yml) Check if Service Exists (RedHat based OS)
|
|
ansible.builtin.shell: 'systemctl list-unit-files | grep -q -e "^{{ item }}.service";'
|
|
changed_when: "service_exists.rc > 1"
|
|
failed_when: "service_exists.rc > 1"
|
|
register: service_exists
|
|
with_items:
|
|
- "{{ redhat_services_active_and_started }}"
|
|
when:
|
|
- ansible_facts.os_family == "RedHat"
|
|
|
|
#- debug: msg="{{ service_exists.results }}"
|
|
|
|
- name: (systemd-services.yml) Check if Service is disabled (RedHat based OS)
|
|
ansible.builtin.shell: 'systemctl list-unit-files | grep -e "^{{ item.item }}.service" | grep -q "disabled";'
|
|
register: service_is_enabled
|
|
changed_when: "service_is_enabled.rc == 0"
|
|
failed_when: "service_is_enabled.rc > 1"
|
|
with_items:
|
|
- "{{ service_exists.results }}"
|
|
loop_control:
|
|
label: "{{ item.item }}"
|
|
when:
|
|
- item.rc == 0
|
|
- ansible_facts.os_family == "RedHat"
|
|
|
|
#- debug: msg="{{ service_is_enabled.results }}"
|
|
|
|
- name: (systemd-services.yml) Enable service
|
|
ansible.builtin.systemd:
|
|
name: "{{ item.item.item }}.service"
|
|
enabled: true
|
|
with_items:
|
|
- "{{ service_is_enabled.results }}"
|
|
loop_control:
|
|
label: "{{ item.item.item }}"
|
|
when:
|
|
- item.changed
|
|
|
|
- name: (systemd-services.yml) Check if Service is active
|
|
ansible.builtin.command: "systemctl is-active {{ item.item }}.service"
|
|
register: service_is_active
|
|
changed_when: 'service_is_active.stdout == "inactive"'
|
|
failed_when: "service_is_active.rc > 3"
|
|
with_items:
|
|
- "{{ service_exists.results }}"
|
|
loop_control:
|
|
label: "{{ item.item }}"
|
|
when:
|
|
- item.rc == 0
|
|
|
|
- name: (systemd-services.yml) Start service
|
|
ansible.builtin.systemd:
|
|
name: "{{ item.item.item }}.service"
|
|
state: started
|
|
with_items:
|
|
- "{{ service_is_active.results }}"
|
|
loop_control:
|
|
label: "{{ item.item.item }}"
|
|
when:
|
|
- item.changed
|