Ansible – Enable and Restart a service

In this case “syslog-ng” has been used.

- hosts: [targethosts]

  become: yes
  become_method: sudo

  tasks:
    - name: Gather Executing User Name
      command: whoami
      always_run: yes
      register: executing_user_id
      delegate_to: 127.0.0.1
    - name: Restart syslog-ng service
      service: name=syslog-ng  state=restarted
    - name: Enable service
      service: name=syslog-ng  enabled=yes

    - name: Start writing to Ansible Log file
      lineinfile: dest="/var/log/ansible_history" line="TI-4003 syslog-ng  -  DATE {{ ansible_date_time.iso8601 }} - USER {{ executing_user_id.stdout }}" create=yes state=present insertafter=EOF
Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.