You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use case is this: I have some playbook which has a few attributes common between a number of steps, but in themselves are not a "complete" step. I would like to have one declaration of these attributes and reference them elsewhere in the playbook:
---
- name: My Playhosts: someHosts# This snippet is not a complete task definition, but is used to reference multiple attributes in a repeatable way.become_app_user: &become_app_userbecome: yesbecome_user: '{{ app_user }}'tasks:
- name: Run task as main ansible useransible.builtin.shell: whoami
- name: run task as the app_user<< : *become_app_useransible.builtin.shell: 'echo "$USER";'
- name: perform some action as app_user<< : *become_app_usersome_action: to_perform
- name: perform action as main ansible user againsome_action: to_perform
I propose we allow attributes prefaced with . at the top level of a play, where ansible will ignore them, but they can be used for anchors and attribute merging
There was a previous request for this on the main ansible repo, but there the user was unaware of a simpler way of obtaining the same results as they were just trying to reference configuration multiple times in a host file.
I recognise the above example could be "resolved" by splitting into separate play files, but it is meant as a demonstration of a useful "power" that seems to be arbitrarily denied to users at this time: If we allow . prefixed attributes at the top level of a play, we allow for snippets to be reused.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The use case is this: I have some playbook which has a few attributes common between a number of steps, but in themselves are not a "complete" step. I would like to have one declaration of these attributes and reference them elsewhere in the playbook:
I propose we allow attributes prefaced with
.
at the top level of a play, where ansible will ignore them, but they can be used for anchors and attribute mergingThere was a previous request for this on the main ansible repo, but there the user was unaware of a simpler way of obtaining the same results as they were just trying to reference configuration multiple times in a host file.
I recognise the above example could be "resolved" by splitting into separate play files, but it is meant as a demonstration of a useful "power" that seems to be arbitrarily denied to users at this time: If we allow
.
prefixed attributes at the top level of a play, we allow for snippets to be reused.The change to the playbook schema is small:
Is there any technical risk for this kind of thing? Would it also need a change in the ansible parser? or would it safely ignore the unused properties
Beta Was this translation helpful? Give feedback.
All reactions