Refactor Ansible tasks to use fully qualified module names and improve code consistency
- 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.
This commit is contained in:
@@ -1,64 +1,61 @@
|
||||
---
|
||||
|
||||
- name: (systemd-services.yml) Check if Service Exists (RedHat based OS)
|
||||
shell: 'systemctl list-unit-files | grep -q -e "^{{ item }}.service";'
|
||||
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:
|
||||
with_items:
|
||||
- "{{ redhat_services_active_and_started }}"
|
||||
when:
|
||||
when:
|
||||
- ansible_facts.os_family == "RedHat"
|
||||
|
||||
#- debug: msg="{{ service_exists.results }}"
|
||||
|
||||
- name: (systemd-services.yml) Check if Service is disabled (RedHat based OS)
|
||||
shell: 'systemctl list-unit-files | grep -e "^{{ item.item }}.service" | grep -q "disabled";'
|
||||
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:
|
||||
with_items:
|
||||
- "{{ service_exists.results }}"
|
||||
loop_control:
|
||||
label: '{{ item.item }}'
|
||||
when:
|
||||
- item.rc == 0
|
||||
label: "{{ item.item }}"
|
||||
when:
|
||||
- item.rc == 0
|
||||
- ansible_facts.os_family == "RedHat"
|
||||
|
||||
#- debug: msg="{{ service_is_enabled.results }}"
|
||||
|
||||
- name: (systemd-services.yml) Enable service
|
||||
systemd:
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item.item.item }}.service"
|
||||
enabled: true
|
||||
with_items:
|
||||
- "{{ service_is_enabled.results }}"
|
||||
loop_control:
|
||||
label: '{{ item.item.item }}'
|
||||
label: "{{ item.item.item }}"
|
||||
when:
|
||||
- item.changed
|
||||
|
||||
- name: (systemd-services.yml) Check if Service is active
|
||||
shell: 'systemctl is-active {{ item.item }}.service'
|
||||
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'
|
||||
failed_when: "service_is_active.rc > 3"
|
||||
with_items:
|
||||
- "{{ service_exists.results }}"
|
||||
loop_control:
|
||||
label: '{{ item.item }}'
|
||||
label: "{{ item.item }}"
|
||||
when:
|
||||
- item.rc == 0
|
||||
|
||||
|
||||
|
||||
- name: (systemd-services.yml) Start service
|
||||
systemd:
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item.item.item }}.service"
|
||||
state: started
|
||||
with_items:
|
||||
- "{{ service_is_active.results }}"
|
||||
loop_control:
|
||||
label: '{{ item.item.item }}'
|
||||
label: "{{ item.item.item }}"
|
||||
when:
|
||||
- item.changed
|
||||
|
||||
Reference in New Issue
Block a user