One way to use ansible to identify AWS rds instances that have specific tags and exclude them from the result is to use the tag query options for the ec2_vpc_net_facts
module.
Here's an example playbook that uses ec2_vpc_net_facts
to query for RDS instances that have a specific Environment
tag and then uses the selectattr
filter to exclude any instances that have a Status
tag matching production
:
- name: Find non-production RDS instances
hosts: localhost
gather_facts: False
vars:
region: us-west-2
environment_tag: Environment:dev
tasks:
- name: Get RDS instances with environment tag
ec2_vpc_net_facts:
region: "{{ region }}"
filters:
tag: "{{ environment_tag }}"
refresh_cache: true
register: results
- name: Filter out production instances
set_fact:
rds_nonprod: "{{ results.vpcs[0].rds_instances | selectattr('tags.Status', 'ne', 'production') | list }}"
- name: Print non-production instances
debug:
var: rds_nonprod
In this example, we are using the ec2_vpc_net_facts
module to query for RDS instances in the us-west-2
region that have the Environment:dev
tag. We then register the results in the results
variable.
Next, we use the set_fact
module to create a new rds_nonprod
variable. Here we use the selectattr
filter to exclude any instances that have a Status
tag matching production
, and then convert the result to a list.
Finally, we use the debug
module to print out the rds_nonprod
variable, which will contain a list of all RDS instances with the Environment:dev
tag, excluding any instances with a Status
tag matching production
.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-11-29 11:00:00 +0000
Seen: 10 times
Last updated: Jan 14 '23
What is the method for utilizing jq with streams to parse information about Amazon's RDS instances?
How can you ensure the safe operation of an Apache container on Kubernetes?
How can I use VS Code and R to create plots?
How can folders be created for each month using react pdf?
What is the meaning of the term deprecated with regards to react-google-login?
How can I use .populate() in Mongoose to select specific fields?
What explains the variation in performance between the benchmark's C version and its AVX2 version?
What is the process for preserving all Docker images and transferring them to a different device?