Types and Tailcalls

Ansible Delegation and Local Actions

published on February 17, 2016

Delegation

Use the delegate_to keyword to perform a task on one host with reference to other hosts. Example:

---
- hosts: webservers
  tasks:
  - name: run echo 'Hello world' on localhost
    command: /bin/echo 'Hello, world!'
    delegate_to: 127.0.0.1

This runs on the machine running ansible.

local_action

Is just a shortcut for delegate_to: 127.0.0.1. The example above could be changed to

---
- hosts: webservers
  tasks:
  - name: run echo 'Hello world' on localhost
    local_action: command /bin/echo 'Hello, world!'

Personally, I find this latter syntax a bit confusing.

Local Playbooks

it is also possible to run an entire playbook locally. Not sure if this is useful in the setup of cloud vms.

This is achieved by either passing the --connection=local flag on the command line when calling ansible-playbook or by setting

- hosts: 127.0.0.1
  connection: local

in the playbook.


comments powered by Disqus