Comments (7)
Thanks for the explanation, @sivel . This behaviour is not mentioned in the documentation and I think it's highly counterintuitive. Also, it's not an issue only with inventory_hostname
, please consider the following playbook:
---
- name: Test pause
hosts: testhosts
gather_facts: no
tasks:
- local_action: set_fact pause_needed=true
when: inventory_hostname == 'hostb'
- local_action: pause seconds=5
when: pause_needed is defined and pause_needed
I think it would be reasonable to assume that the above playbook would pause for 5 seconds at hostb, but this does not happen:
PLAY [Test pause] *************************************************************
TASK: [set_fact pause_needed=true] ********************************************
skipping: [hosta -> 127.0.0.1]
skipping: [hostc -> 127.0.0.1]
skipping: [hostd -> 127.0.0.1]
ok: [hostb -> 127.0.0.1]
TASK: [pause seconds=5] *******************************************************
skipping: [hosta -> 127.0.0.1]
PLAY RECAP ********************************************************************
hosta : ok=0 changed=0 unreachable=0 failed=0
hostb : ok=1 changed=0 unreachable=0 failed=0
hostc : ok=0 changed=0 unreachable=0 failed=0
hostd : ok=0 changed=0 unreachable=0 failed=0
How would you achieve the following?
- Update a configuration on a number of hosts and register the result (
register: update
) - Restart the affected services
when: update.changed
- Pause for a moment after each restart so that the cluster can realign itself (I tried to use
pause ... when: update.changed
for this but, obviously, failed)
from ansible-modules-core.
@mpdehaan - I had the same issue. pause
is not well understood and/or explained.
from ansible-modules-core.
The pause
action_plugin is what is referred to as a host list bypass plugin. This means that pause
will not execute for every host targeted by a playbook. Instead pause
will only execute on the first host in the hosts list as defined by inventory. Due to this, inventory_hostname
will always evaluate to hosta
, making some of your when
statements false.
With that understanding, your tasks are doing what they are instructed to do.
from ansible-modules-core.
You can not reliably use host facts (host_vars, gathered facts, set_fact, registered vars) in a when statement with a host list bypass plugin.
As mentioned, ansible will only run pause
for the first host as defined by inventory. This means that you are inspecting host facts for only that first host, and no other hosts.
You can utilize hostvars['somehost']['somevar']
to access vars for other hosts. That in combination with with_items
could help, but you could find yourself pausing for every host in the play per pause task. So if you had 300 hosts, and you used with_items: play_hosts
and had when: hostvars[item]['update']|changed
it could sleep 300 times for 5 seconds each which equates to 25 minutes of pauses.
The better solution, instead of using a pause, would be to use wait_for
and actually wait for something to happen, as opposed to an arbitrary pause.
from ansible-modules-core.
I'm going to close this one because of the host loop misunderstanding above, if there are further questions, discussion on ansible-project is quite welcome.
Thanks!
from ansible-modules-core.
@sivel , wait_for
with a delay is what I ended up using to work around this, but I still think that this behaviour is counterintuitive. Also, sometimes there may not be anything externally accessible to wait for (for example, you might just want to allow some time for a cache to warm up).
@mpdehaan , at the very least this should be clearly pointed out in the documentation. I would be surprised if I was the first one to be confused by this.
Anyway, thanks for the clarification, guys.
from ansible-modules-core.
@sivel Thanks for the loop suggestion. In my case wait_for
was not an option and I really required a conditional pause for every host the user has to confirm. With a loop this indeed works. If anyone else needs something like this, I posted my solution on SO: http://stackoverflow.com/a/35169496/2753241
from ansible-modules-core.
Related Issues (20)
- .. HOT 1
- azure_rm_deployment: InvalidClientIdError: (invalid_request) AADSTS90002: Requested tenant identifier 'xxxxxx.com'' is not valid. HOT 1
- 'dict object' has no attribute 'stdout' HOT 1
- unarchive does not work for .zip file on ansible 2.2.1 on windows Environment HOT 1
- async polling doesnt work HOT 1
- ansible_s3 does not support delegate_to HOT 2
- vyos_config has timeout after some unknown number of commands HOT 1
- Include_vars in free-form mode requires a file extension, breaking reverse compatibility HOT 1
- pushing jinja2 configurations on to network devices HOT 1
- 'list' object has no attribute 'items'\r\n" HOT 3
- Cisco Nexus N3K - QinQ issue HOT 1
- "msg": "failed to create temporary content file: timed out". Can someone help me on this. HOT 1
- Uri module modifies + sign to spaces HOT 1
- template error while templating string: unexpected ']' After Dictionary Combine HOT 1
- Yum install with Corrupt repo endless loop HOT 1
- ios_command failure for cisco with rc=1 HOT 2
- nxos_interface module does not work HOT 1
- ios_config backup not working on windows shared drive HOT 2
- ansible_module_azure_rm_virtualmachine incompatible with Python3 HOT 1
- Path parameter should work like file copy module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-modules-core.