0

I want to gather inforamtion of a service's & command status in a file via ansible playbook role. is there any way to get those date in a file like below. As there are multiple task on which we need to get status off.

<serverip> snmp inactive
<serverip1> snmp active
<serverip2> snmp active

or

<serverip3> snmp 0
<serverip4> snmp 1

Something like this.

Below is a sample script which we am executing currently.

    ---
    - name: read snmp service status
      block:
        - name: get sysctl snmp services status [PRE]
          shell: "service snmp status"
          ignore_errors: true
          register: snmp
        - name: set fact snmp
          set_fact:
            results_pre: "{{ results_pre|combine({'snmp': snmp.stdout.replace(\"'\", '\"')|quote }) }}"
        - name: write snmp service status
          copy:
            dest: "{{ remote_logs_path }}/{{ ansible_ssh_host }}/pre/snmp"
            content: "{{ snmp.stdout }}"
      tags:
        - snmp

1 Answer 1

0

To gather the status of a service via Ansible Playbooks it is recommended to use the service_facts module.

- name: Gathering Service Facts
  service_facts:

You can than write the status into a log file based on Conditionals and facts.

- name: Write SNMP service status
    ...
  when: ("snmp.service" in services)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .