---
- hosts: all
  vars_files:
    - /etc/rocknsm/config.yml
  tasks:
    - name: Populate service facts
      service_facts:

    - name: Flatten ROCK services
      set_fact:
        flat_services: "{{ ansible_facts.services | flatten(levels=1) | replace('.service', '')  }}"

    - name: Collect ROCK services from facts
      set_fact:
        host_services: "{{ flat_services | intersect(enabled_services) }}"

    - name: Perform requested service action
      service:
        name: "{{ item }}"
        state: "{{ service_action }}"
      loop: "{{ host_services }}"
      tags:
        - service_mgmt

    - name: Register service status
      shell: systemctl status -n 3 {{ item }}*
      loop: "{{ host_services }}"
      register: services
      changed_when: false
      tags:
        - service_status

    - name: Output service status
      debug:
        msg:  "{{ item.stdout }}"
      loop: "{{ services.results }}"
      loop_control:
        label: "{{ item._ansible_item_label }}"
      tags:
        - service_status

Add playbook to manage services
Add playbook to manage services
