published on February 17, 2016
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.
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.
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.