Repository navigation
Conversation
| 'ansible_dependent_role_names', | ||
| 'ansible_play_role_names', | ||
| 'ansible_role_names', | ||
| 'ansible_play_strategy', |
There was a problem hiding this comment.
this should be undefined in hostvars context, no need to add it here
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
We're trying to cut down on the use of top-level names for these things, so rather than making another magic var, we should define global objects to expose these things, and also make it clear that they're not settable and effectively reserved names. |
|
@nitzmahone - That sounds like reasonable goals. But I don't know how to translate that into working code. Are there existing instances of such global objects I can refer to for examples? |
|
@utoddl There will be, early-ish in the 2.18 timeframe... Once the new infrastructure for creating and exposing them is in place, my hope is to re-implement a bunch of the "magic vars" and siloed state management that's currently scattered all over the codebase on top of these new contextvars + context manager accessors. There'd be a handful of them used as the actual state storage for things like PlayIterator, TaskQueueManager, TaskExecutor, etc, then we do a little bit of dynamic vars magic to plumb them through to our vars system and Jinja (hopefully with a more sustainable/extensible access and naming hierarchy than discrete |
|
Does this count as "early-ish in the 2.18 timeframe" yet, @nitzmahone? My one-line 13-month-old PR – which I just updated to work with current I appreciate not wanting to dig a technical debt hole any deeper, but it seems whatever means will be used to transition Meanwhile, we're still faced with the same (reasonable) warning from |
SUMMARY
Create the magic variable
ansible_play_strategywhich makes the current play's strategy visible to tasks.With this information, it becomes possible to take active precautions against the unexpected behavior
ansible-lintwarns about when combiningstrategy: freeandrun_once: true. For example, one could fail the play with a message like, "Don't run this play withstrategy: freebecause it usesrun_once." Or one could include a set of tasks more appropriate for the current strategy, a decision which isn't limited to thestrategy: freecase.Without this info (i.e. currently), the only possible action is to ignore
ansible-lint's warning, either with anoqaor tweaking theansible-lintconfig file. That gets past linting, but there's nothing more you can do. If someone subsequently setsstrategy: free, then they'll suffer the consequences that would have been mentioned in the suppressed warnings.Note: you'll have to suppress
ansible-lint's warnings in either case to pass linting. But at least withansible_play_strategyexposed as a magic variable, you can take additional safeguards in the play itself, an option which isn't available to you withoutansible_play_strategy.ISSUE TYPE
ADDITIONAL INFORMATION
This change has an extremely small footprint. There's not much more to say about it.
Here's a simple playbook with two plays, the first with
strategy: freeand the second without specifying a strategy.And here's the output: