Ansible and Local Execution

How can I execute an Ansible task on the local Ansible controller server?

The key is to use the “delegate_to” or “local_action” key words on your task.

So lets say we want to use Ansible to monitor an end point and perform some action if the response is not equal to 200.

  1. Create task to check URL using the URI module and “delegate_to” or do step #2

    • – name: Endpoint Validator
      uri:
      url: “{{ url }}”
      delegate_to: 127.0.0.1
      register: response
  2. Create task to check URL using the URI module and “local_action

    • – name: Endpoint Validator
      uri:
      local_action: url “{{ url }}”
      register: response
  3. Create task to perform action (e.g. fail) if response it not 200

    • – name: Endpoint Error Action
      fail:
      when: response.status != 200

Ansible_Linux_www.hackthesec.co_.in_