Reputation: 475
I'm setting up a small project in ansible, with a shared node with other projects. This node is the CI runner, and should rarely be the target of a playbook.
I want to exclude a group from all
by default
The current solution that I have is just to have a group called bystanders, and exclude it from all playbooks that run all
hosts:
[groupA]
node1
[bystanders]
ci-node
playbook_example:
hosts: all:!bystanders
...
But this is prone to error, or forgetting to exclude that in some playbook, inadvertently running a playbook on that node.
Upvotes: 4
Views: 5586
Reputation: 475
I asked this question somewhere else, and Dynamic inventory scripts were mentioned.
The dynamic inventory returns 'all' and 'ungrouped', so we can manipulate the results for these variables with dynamic inventory scripts.
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {}
}
However, in that conversation it was mentioned that 'all' is a bit of an anti-pattern, and avoiding it might be a good idea in the first place. 'all' means all, and in this case nothing that is project specific should use 'all'.
So I think this answers the question for me. I will avoid the use of all and in case I really need to do this, I will go with the dynamic inventory scripts
Upvotes: 3