Ansible: How to run one Task Host by Host?Serialization with Ansible with a jumpbox/build-serverHow to see stdout of ansible commands?How can I implement ansible with per-host passwords, securely?Run included ansible task as standalone taskAnsible: Execute task only when a tag is specifiedCallbacks or hooks, and reusable series of tasks, in Ansible rolesAnsible role post tasksAnsible Multiple Application Role Approachansible how to get host from inventory in taskAnsible known_hosts task failsAnsible: Run 1 task on 1 host under several users
Is there an efficient way to replace text matching the entire content of one file with the entire content of another file?
Is cutting a DIY spline channel around the openings of our wood screen porch a dumb idea?
Looking for a soft substance that doesn't dissolve underwater
Wireless Multipoint Bridging / Backhaul Gateway Antenna and AP Selection
Why colon to denote that a value belongs to a type?
Would Brexit have gone ahead by now if Gina Miller had not forced the Government to involve Parliament?
Does revoking a certificate result in revocation of its key?
Using the smallest number of bytes of code, write a program that produces this image
Why is this Simple Puzzle impossible to solve?
Should breaking down something like a door be adjudicated as an attempt to beat its AC and HP, or as an ability check against a set DC?
Ticket sales for Queen at the Live Aid
Boss wants me to falsify a report. How should I document this unethical demand?
Forward and backward integration -- cause of errors
What are these arcade games in Ghostbusters 1984?
How can people dance around bonfires on Lag Lo'Omer - it's darchei emori?
Does this degree 12 genus 1 curve have only one point over infinitely many finite fields?
Seed ship, unsexed person, cover has golden person attached to ship by umbilical cord
Is the Indo-European language family made up?
Can R-3-methyl-4-heptanone be enantioselectively synthesised from 4-heptanone?
What is the largest (size) solid object ever dropped from an airplane to impact the ground in freefall?
At what point in European history could a government build a printing press given a basic description?
How strong are Wi-Fi signals?
What is the most important source of natural gas? coal, oil or other?
Where did Carnap express his disagreement with Wittgenstein's Tractatus?
Ansible: How to run one Task Host by Host?
Serialization with Ansible with a jumpbox/build-serverHow to see stdout of ansible commands?How can I implement ansible with per-host passwords, securely?Run included ansible task as standalone taskAnsible: Execute task only when a tag is specifiedCallbacks or hooks, and reusable series of tasks, in Ansible rolesAnsible role post tasksAnsible Multiple Application Role Approachansible how to get host from inventory in taskAnsible known_hosts task failsAnsible: Run 1 task on 1 host under several users
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
On the play-level, we have serial: 1 to allow us to run the whole play one host at a time. But I haven't found a simple way to do this on a single task. This is especially relevant, if the task in question doesn't perform proper locking (for whatever reason).
One obvious answer is to put the task in its own play. But that doesn't help with roles. (Having to put serial: 1 on the play using the role isn't really intuitive.)
ansible
add a comment |
On the play-level, we have serial: 1 to allow us to run the whole play one host at a time. But I haven't found a simple way to do this on a single task. This is especially relevant, if the task in question doesn't perform proper locking (for whatever reason).
One obvious answer is to put the task in its own play. But that doesn't help with roles. (Having to put serial: 1 on the play using the role isn't really intuitive.)
ansible
add a comment |
On the play-level, we have serial: 1 to allow us to run the whole play one host at a time. But I haven't found a simple way to do this on a single task. This is especially relevant, if the task in question doesn't perform proper locking (for whatever reason).
One obvious answer is to put the task in its own play. But that doesn't help with roles. (Having to put serial: 1 on the play using the role isn't really intuitive.)
ansible
On the play-level, we have serial: 1 to allow us to run the whole play one host at a time. But I haven't found a simple way to do this on a single task. This is especially relevant, if the task in question doesn't perform proper locking (for whatever reason).
One obvious answer is to put the task in its own play. But that doesn't help with roles. (Having to put serial: 1 on the play using the role isn't really intuitive.)
ansible
ansible
asked Nov 15 '15 at 1:24
ElrondElrond
2761315
2761315
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
If you don't want any parallelism in performing the steps in your playbook, set the fork level to 1:
ansible-playbook --forks=1 ...
You can also put this in your ansible cfg file:
[defaults]
forks=1
but if you want it on an individual basis, use the command line option above.
EDIT:
serial: 1 does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched.
So you want forks=1 for just one play; unfortunately that is not currently possible.
2
I was not looking to set this on a whole playbook. That's much to non-granular.serial: 1let's me set it on a play at least. But I only want to set it on a subitem of a play (what ever the correct name of that is. I thought, it was "task", but comment above seems to disagree).
– Elrond
Nov 18 '15 at 20:46
3
serial: 1does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host.forks=1means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. So you wantforks=1for just one play; unfortunately that is not currently possible.
– wurtel
Nov 20 '15 at 15:43
Good point! Would you mind adding that to the answer?
– Elrond
Nov 20 '15 at 20:49
add a comment |
If you are executing it on a single machine , then exclusive locks issue arises for more than one host .So you should execute one by one for all the hosts .For this you need to have --forks=1 being set when calling ansible playbook command.
FOr example: ansible-playbook webserver.yml --forks=1 where webserver.yml has app01 and app02 inside your [webserver]
add a comment |
Think what you want is
run_once: true
3
nope: "run_once: true" means to run the task for exactly one host in the list of hosts. I want to run it for each host in the list, but one after the other.
– Elrond
Oct 24 '16 at 19:50
add a comment |
For commands that can be run locally, use a loop to iterate over all the hosts in the play. This ONLY works if the command can be run locally. You could also run a command with ssh in it to the remote machines one by one in this manner, if keys are setup, but it becomes difficult when talking about escalation.
EG:
- name: Init New Appliances - Remove the known hosts entry for the server in case it has changed
run_once: yes
connection: local
become: no
command: "ssh-keygen -R item "
with_items:
- " inventory_hostname "
1
You have to provide a list of hosts instead of just on host namedinventory_hostname, otherwise the loop makes no sense.
– Konstantin Suvorov
May 24 '17 at 11:45
add a comment |
There's a workaround to this problem - one can pass list of hosts (or a group) to with_items, and then use delegate_to with this list. This way task will be executed host by host.
For example:
- name: start and enable rabbitmq (run task host by host)
service:
name: "rabbitmq-server"
state: "started"
enabled: true
delegate_to: " item "
with_items: " groups['rabbitmq-cluster'] "
run_once: true
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f736452%2fansible-how-to-run-one-task-host-by-host%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you don't want any parallelism in performing the steps in your playbook, set the fork level to 1:
ansible-playbook --forks=1 ...
You can also put this in your ansible cfg file:
[defaults]
forks=1
but if you want it on an individual basis, use the command line option above.
EDIT:
serial: 1 does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched.
So you want forks=1 for just one play; unfortunately that is not currently possible.
2
I was not looking to set this on a whole playbook. That's much to non-granular.serial: 1let's me set it on a play at least. But I only want to set it on a subitem of a play (what ever the correct name of that is. I thought, it was "task", but comment above seems to disagree).
– Elrond
Nov 18 '15 at 20:46
3
serial: 1does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host.forks=1means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. So you wantforks=1for just one play; unfortunately that is not currently possible.
– wurtel
Nov 20 '15 at 15:43
Good point! Would you mind adding that to the answer?
– Elrond
Nov 20 '15 at 20:49
add a comment |
If you don't want any parallelism in performing the steps in your playbook, set the fork level to 1:
ansible-playbook --forks=1 ...
You can also put this in your ansible cfg file:
[defaults]
forks=1
but if you want it on an individual basis, use the command line option above.
EDIT:
serial: 1 does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched.
So you want forks=1 for just one play; unfortunately that is not currently possible.
2
I was not looking to set this on a whole playbook. That's much to non-granular.serial: 1let's me set it on a play at least. But I only want to set it on a subitem of a play (what ever the correct name of that is. I thought, it was "task", but comment above seems to disagree).
– Elrond
Nov 18 '15 at 20:46
3
serial: 1does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host.forks=1means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. So you wantforks=1for just one play; unfortunately that is not currently possible.
– wurtel
Nov 20 '15 at 15:43
Good point! Would you mind adding that to the answer?
– Elrond
Nov 20 '15 at 20:49
add a comment |
If you don't want any parallelism in performing the steps in your playbook, set the fork level to 1:
ansible-playbook --forks=1 ...
You can also put this in your ansible cfg file:
[defaults]
forks=1
but if you want it on an individual basis, use the command line option above.
EDIT:
serial: 1 does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched.
So you want forks=1 for just one play; unfortunately that is not currently possible.
If you don't want any parallelism in performing the steps in your playbook, set the fork level to 1:
ansible-playbook --forks=1 ...
You can also put this in your ansible cfg file:
[defaults]
forks=1
but if you want it on an individual basis, use the command line option above.
EDIT:
serial: 1 does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched.
So you want forks=1 for just one play; unfortunately that is not currently possible.
edited Nov 25 '15 at 9:06
answered Nov 16 '15 at 15:30
wurtelwurtel
3,118613
3,118613
2
I was not looking to set this on a whole playbook. That's much to non-granular.serial: 1let's me set it on a play at least. But I only want to set it on a subitem of a play (what ever the correct name of that is. I thought, it was "task", but comment above seems to disagree).
– Elrond
Nov 18 '15 at 20:46
3
serial: 1does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host.forks=1means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. So you wantforks=1for just one play; unfortunately that is not currently possible.
– wurtel
Nov 20 '15 at 15:43
Good point! Would you mind adding that to the answer?
– Elrond
Nov 20 '15 at 20:49
add a comment |
2
I was not looking to set this on a whole playbook. That's much to non-granular.serial: 1let's me set it on a play at least. But I only want to set it on a subitem of a play (what ever the correct name of that is. I thought, it was "task", but comment above seems to disagree).
– Elrond
Nov 18 '15 at 20:46
3
serial: 1does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host.forks=1means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. So you wantforks=1for just one play; unfortunately that is not currently possible.
– wurtel
Nov 20 '15 at 15:43
Good point! Would you mind adding that to the answer?
– Elrond
Nov 20 '15 at 20:49
2
2
I was not looking to set this on a whole playbook. That's much to non-granular.
serial: 1 let's me set it on a play at least. But I only want to set it on a subitem of a play (what ever the correct name of that is. I thought, it was "task", but comment above seems to disagree).– Elrond
Nov 18 '15 at 20:46
I was not looking to set this on a whole playbook. That's much to non-granular.
serial: 1 let's me set it on a play at least. But I only want to set it on a subitem of a play (what ever the correct name of that is. I thought, it was "task", but comment above seems to disagree).– Elrond
Nov 18 '15 at 20:46
3
3
serial: 1 does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. So you want forks=1 for just one play; unfortunately that is not currently possible.– wurtel
Nov 20 '15 at 15:43
serial: 1 does something completely different: that is like running the playbook for each host in turn, waiting for completion of the complete playbook before moving on to the next host. forks=1 means run the first task in a play on one host before running the same task on the next host, so the first task will be run for each host before the next task is touched. So you want forks=1 for just one play; unfortunately that is not currently possible.– wurtel
Nov 20 '15 at 15:43
Good point! Would you mind adding that to the answer?
– Elrond
Nov 20 '15 at 20:49
Good point! Would you mind adding that to the answer?
– Elrond
Nov 20 '15 at 20:49
add a comment |
If you are executing it on a single machine , then exclusive locks issue arises for more than one host .So you should execute one by one for all the hosts .For this you need to have --forks=1 being set when calling ansible playbook command.
FOr example: ansible-playbook webserver.yml --forks=1 where webserver.yml has app01 and app02 inside your [webserver]
add a comment |
If you are executing it on a single machine , then exclusive locks issue arises for more than one host .So you should execute one by one for all the hosts .For this you need to have --forks=1 being set when calling ansible playbook command.
FOr example: ansible-playbook webserver.yml --forks=1 where webserver.yml has app01 and app02 inside your [webserver]
add a comment |
If you are executing it on a single machine , then exclusive locks issue arises for more than one host .So you should execute one by one for all the hosts .For this you need to have --forks=1 being set when calling ansible playbook command.
FOr example: ansible-playbook webserver.yml --forks=1 where webserver.yml has app01 and app02 inside your [webserver]
If you are executing it on a single machine , then exclusive locks issue arises for more than one host .So you should execute one by one for all the hosts .For this you need to have --forks=1 being set when calling ansible playbook command.
FOr example: ansible-playbook webserver.yml --forks=1 where webserver.yml has app01 and app02 inside your [webserver]
answered May 30 '18 at 13:00
Rohan SethRohan Seth
1111
1111
add a comment |
add a comment |
Think what you want is
run_once: true
3
nope: "run_once: true" means to run the task for exactly one host in the list of hosts. I want to run it for each host in the list, but one after the other.
– Elrond
Oct 24 '16 at 19:50
add a comment |
Think what you want is
run_once: true
3
nope: "run_once: true" means to run the task for exactly one host in the list of hosts. I want to run it for each host in the list, but one after the other.
– Elrond
Oct 24 '16 at 19:50
add a comment |
Think what you want is
run_once: true
Think what you want is
run_once: true
answered Aug 11 '16 at 18:31
user19151user19151
172
172
3
nope: "run_once: true" means to run the task for exactly one host in the list of hosts. I want to run it for each host in the list, but one after the other.
– Elrond
Oct 24 '16 at 19:50
add a comment |
3
nope: "run_once: true" means to run the task for exactly one host in the list of hosts. I want to run it for each host in the list, but one after the other.
– Elrond
Oct 24 '16 at 19:50
3
3
nope: "run_once: true" means to run the task for exactly one host in the list of hosts. I want to run it for each host in the list, but one after the other.
– Elrond
Oct 24 '16 at 19:50
nope: "run_once: true" means to run the task for exactly one host in the list of hosts. I want to run it for each host in the list, but one after the other.
– Elrond
Oct 24 '16 at 19:50
add a comment |
For commands that can be run locally, use a loop to iterate over all the hosts in the play. This ONLY works if the command can be run locally. You could also run a command with ssh in it to the remote machines one by one in this manner, if keys are setup, but it becomes difficult when talking about escalation.
EG:
- name: Init New Appliances - Remove the known hosts entry for the server in case it has changed
run_once: yes
connection: local
become: no
command: "ssh-keygen -R item "
with_items:
- " inventory_hostname "
1
You have to provide a list of hosts instead of just on host namedinventory_hostname, otherwise the loop makes no sense.
– Konstantin Suvorov
May 24 '17 at 11:45
add a comment |
For commands that can be run locally, use a loop to iterate over all the hosts in the play. This ONLY works if the command can be run locally. You could also run a command with ssh in it to the remote machines one by one in this manner, if keys are setup, but it becomes difficult when talking about escalation.
EG:
- name: Init New Appliances - Remove the known hosts entry for the server in case it has changed
run_once: yes
connection: local
become: no
command: "ssh-keygen -R item "
with_items:
- " inventory_hostname "
1
You have to provide a list of hosts instead of just on host namedinventory_hostname, otherwise the loop makes no sense.
– Konstantin Suvorov
May 24 '17 at 11:45
add a comment |
For commands that can be run locally, use a loop to iterate over all the hosts in the play. This ONLY works if the command can be run locally. You could also run a command with ssh in it to the remote machines one by one in this manner, if keys are setup, but it becomes difficult when talking about escalation.
EG:
- name: Init New Appliances - Remove the known hosts entry for the server in case it has changed
run_once: yes
connection: local
become: no
command: "ssh-keygen -R item "
with_items:
- " inventory_hostname "
For commands that can be run locally, use a loop to iterate over all the hosts in the play. This ONLY works if the command can be run locally. You could also run a command with ssh in it to the remote machines one by one in this manner, if keys are setup, but it becomes difficult when talking about escalation.
EG:
- name: Init New Appliances - Remove the known hosts entry for the server in case it has changed
run_once: yes
connection: local
become: no
command: "ssh-keygen -R item "
with_items:
- " inventory_hostname "
answered May 24 '17 at 11:21
MicheleMichele
11
11
1
You have to provide a list of hosts instead of just on host namedinventory_hostname, otherwise the loop makes no sense.
– Konstantin Suvorov
May 24 '17 at 11:45
add a comment |
1
You have to provide a list of hosts instead of just on host namedinventory_hostname, otherwise the loop makes no sense.
– Konstantin Suvorov
May 24 '17 at 11:45
1
1
You have to provide a list of hosts instead of just on host named
inventory_hostname, otherwise the loop makes no sense.– Konstantin Suvorov
May 24 '17 at 11:45
You have to provide a list of hosts instead of just on host named
inventory_hostname, otherwise the loop makes no sense.– Konstantin Suvorov
May 24 '17 at 11:45
add a comment |
There's a workaround to this problem - one can pass list of hosts (or a group) to with_items, and then use delegate_to with this list. This way task will be executed host by host.
For example:
- name: start and enable rabbitmq (run task host by host)
service:
name: "rabbitmq-server"
state: "started"
enabled: true
delegate_to: " item "
with_items: " groups['rabbitmq-cluster'] "
run_once: true
add a comment |
There's a workaround to this problem - one can pass list of hosts (or a group) to with_items, and then use delegate_to with this list. This way task will be executed host by host.
For example:
- name: start and enable rabbitmq (run task host by host)
service:
name: "rabbitmq-server"
state: "started"
enabled: true
delegate_to: " item "
with_items: " groups['rabbitmq-cluster'] "
run_once: true
add a comment |
There's a workaround to this problem - one can pass list of hosts (or a group) to with_items, and then use delegate_to with this list. This way task will be executed host by host.
For example:
- name: start and enable rabbitmq (run task host by host)
service:
name: "rabbitmq-server"
state: "started"
enabled: true
delegate_to: " item "
with_items: " groups['rabbitmq-cluster'] "
run_once: true
There's a workaround to this problem - one can pass list of hosts (or a group) to with_items, and then use delegate_to with this list. This way task will be executed host by host.
For example:
- name: start and enable rabbitmq (run task host by host)
service:
name: "rabbitmq-server"
state: "started"
enabled: true
delegate_to: " item "
with_items: " groups['rabbitmq-cluster'] "
run_once: true
answered May 14 at 12:55
Tomasz KlosinskiTomasz Klosinski
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f736452%2fansible-how-to-run-one-task-host-by-host%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown