Ansible delegate to module

Ansible delegate_to module

If you want to run any task on any particular machine you can use ansible delegate_to module. In the following steps i will show how to use ansible delegate to module with different examples.

Here first task will run on all hosts in web group but second task will run on only web.jboss.etm1  machine.

ansible delegate to localhost

If you want to run the task on local ansible control machine you can use this module. Or you can use ansible local_action module.

In this playbook you can mention 127.0.0.1 or localhost both refers to ansible control machine.

In this playbook the first task will run on local ansible control machine and second task will run on all webservers group of machines.

ansible local_action

You can modify above playbook by using local_action in the place of delegate_to 127.0.0.1(localhost).

Both above two playbooks will give the same result.

 

  • ansible delegate_to example
  •  group delegate_to ansible
  • ansible delegate_to not working
  • delegate_to ansible  inventory host
  • ansible delegate_to user password
  • delegate to ansible  group of hosts
  • ansible delegate to first host in group
  • delegate to ansible  remote host
  • ansible delegate to current host
  • delegate to ansible localhost