PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 27, 2022

[FIXED] How to exclude an inventory group from 'all' by default in Ansible?

 September 27, 2022     ansible, ansible-inventory, continuous-deployment     No comments   

Issue

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.


Solution

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



Answered By - Isidoro
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing