-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow filtering of instances by tags in GCE dynamic inventory #35770
Conversation
We’ve found value in this in automation where many inventories are in the same GCP project. The filter prevents accidental typos from blowing out every host within the project. Effectively a safety barrier for automation. |
contrib/inventory/gce.py
Outdated
@@ -247,6 +247,20 @@ def get_config(self): | |||
if states: | |||
self.instance_states = states.split(',') | |||
|
|||
# Set the instance_tags filter | |||
self.instance_tags = [] | |||
if config.has_option('gce', 'instance_tags'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using conditionals for each option, which can be a bit expensive, set a default value when the config
object is created. Then you can just call config.get()
and it will use the default if the key isn't in the file, or it will pull the value from the key in the file.
The test
|
rebuild_merge |
@pschiffe There is a new inventory plugin system in Ansible. In the near future, we will stop accepting new features to scripts in favor of using inventory plugins. While we don't have docs yet, I can point you at some good examples of existing inventory plugins if you're interested in porting this to a plugin. Thanks for your contribution! |
SUMMARY
This enables to exclude instances in the project not relevant to the play, what benefits performance and can help to avoid mistakes.
ISSUE TYPE
COMPONENT NAME
GCE dynamic inventory
ANSIBLE VERSION
/cc @smarterclayton