Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/node_query_database_instance/play.yaml

raw
1 - hosts: localhost
2 gather_facts: true
3
4 roles:
5 - role: setup_node_query
6
7 module_defaults:
8 group/aws:
9 access_key: "{{ aws_access_key }}"
10 secret_key: "{{ aws_secret_key }}"
11 session_token: "{{ security_token | default(omit) }}"
12 region: "{{ aws_region }}"
13
14 vars:
15 engine: mariadb
16 mariadb_engine_version: 11.4.7
17 username: testrdsusername
18 password: "{{ lookup('password', '/dev/null') }}"
19 allocated_storage: 20
20 db_instance_class: db.t3.micro
21
22 rds_instances:
23 - name: "{{ resource_prefix }}-instance-1"
24 tags:
25 Name: "{{ resource_prefix }}-instance-1"
26 Created_by: Ansible Indirect NodeQuery Count integration tests
27 - name: "{{ resource_prefix }}-instance-2"
28
29 rds_instance_facts:
30 device_type: "Instance"
31 infra_bucket: "Database"
32 infra_type: "PublicCloud"
33
34 tasks:
35 - block:
36 # RDS Instances
37 - name: Create a MariaDB instance
38 amazon.aws.rds_instance:
39 db_instance_identifier: "{{ item.name }}"
40 state: present
41 username: "{{ username }}"
42 password: "{{ password }}"
43 engine: "{{ engine }}"
44 engine_version: "{{ mariadb_engine_version }}"
45 db_instance_class: "{{ db_instance_class }}"
46 allocated_storage: "{{ allocated_storage }}"
47 tags: "{{ item.tags | default(omit) }}"
48 loop: "{{ rds_instances }}"
49
50 - name: Get information about the RDS instance
51 amazon.aws.rds_instance_info:
52 filters:
53 db-instance-id:
54 - "{{ resource_prefix }}-instance-1"
55 - "{{ resource_prefix }}-instance-2"
56 register: _instances
57
58 - name: Extract RDS Instances
59 ansible.builtin.set_fact:
60 instance_1: "{{ _instances.instances | selectattr('db_instance_identifier', 'search', 'instance-1') | first }}"
61 instance_2: "{{ _instances.instances | selectattr('db_instance_identifier', 'search', 'instance-2') | first }}"
62
63 - name: Run jq query on result data
64 ansible.builtin.set_fact:
65 node_count: "{{ _instances | to_json | aws_jq(event_node_queries.rds_instance_info) }}"
66
67 - name: Validate result is as expected
68 ansible.builtin.assert:
69 that:
70 - node_count == expected_result
71 vars:
72 expected_result:
73 - canonical_facts:
74 id: "{{ instance_1.dbi_resource_id }}"
75 name: "{{ resource_prefix }}-instance-1"
76 status: "{{ instance_1.db_instance_status }}"
77 tags:
78 Name: "{{ resource_prefix }}-instance-1"
79 Created_by: Ansible Indirect NodeQuery Count integration tests
80 facts: "{{ rds_instance_facts }}"
81 - canonical_facts:
82 id: "{{ instance_2.dbi_resource_id }}"
83 name: "{{ resource_prefix }}-instance-2"
84 status: "{{ instance_2.db_instance_status }}"
85 tags: {}
86 facts: "{{ rds_instance_facts }}"
87
88 always:
89 - name: Delete RDS instances
90 amazon.aws.rds_instance:
91 db_instance_identifier: "{{ item.name }}"
92 state: absent
93 skip_final_snapshot: true
94 wait: false
95 ignore_errors: true
96 loop: "{{ rds_instances }}"