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.
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.
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 .
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).
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.
If you want to run a task that's associated with a host, but on different host, you should try delegate_to
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With