Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: how to run task on other host inside one playbook?

I'm writing ansible playbook for one specific goal: i'd like to sync directory on server A-n, but before i should make git pull on server "B". I launch playbook on host A-n (described in inventory). I also have playbook for "git pull" on server B. Is it possible to include one playbook in another? I don't know how, because ansible allow to specify only one host group in beginning of playbook.

like image 229
Frexin Avatar asked Sep 17 '15 10:09

Frexin


People also ask

How can we delegate tasks in Ansible?

In that case, you need to run that command locally on the remote database servers or on the local ansible host (if needed) and have to delegate permission to the remote database hosts to run the task, so for that specific task, we will use the delegate_to parameter so it can execute the commands remotely.

How do I run a specific part of my playbook in Ansible?

The easiest way to run only one task in Ansible Playbook is using the tags statement parameter of the “ansible-playbook” command. The default behavior is to execute all the tags in your Playbook with --tags all .

How do I run a parallel task in Ansible?

If you want to run multiple tasks in a playbook concurrently, use async with poll set to 0. When you set poll: 0 , Ansible starts the task and immediately moves on to the next task without waiting for a result. Each async task runs until it either completes, fails or times out (runs longer than its async value).

What does Delegate_to mean in Ansible?

As ansible delegate_to is a directive, not an individual module, It integrates with other modules and it controls the task execution by deciding which host should run the task at runtime. Refer to the following snapshot of the playbook, there are few tasks.


1 Answers

If you want to run a task that's associated with a host, but on different host, you should try delegate_to.

like image 148
nghnam Avatar answered Oct 08 '22 02:10

nghnam