AWS dynamic inventory: fixup RDS integration tests (#61259)

* ec2 inventory/rds: (integration tests) migrate to module_defaults and cope with missing security_token

* ec2 inventory/rds: (integration tests) Avoid hard coding the parameter group name

Generated it based on the information returned when creating the RDS instance.

* ec2 inventory/rds: (integration tests) rename templates to .j2 rather than .yml
- avoids throwing yamllint errors
- makes it clear they're templates not the final yaml files.
This commit is contained in:
Mark Chappell 2019-08-25 16:32:18 +02:00 committed by Sloane Hertel
parent a6b124cccc
commit 4e6298b847
9 changed files with 48 additions and 57 deletions

View file

@ -3,7 +3,7 @@
connection: local connection: local
gather_facts: no gather_facts: no
vars: vars:
template_name: "../templates/{{ template | default('inventory.yml') }}" template_name: "../templates/{{ template | default('inventory.j2') }}"
tasks: tasks:
- name: write inventory config file - name: write inventory config file
copy: copy:

View file

@ -5,7 +5,13 @@
environment: "{{ ansible_test.environment }}" environment: "{{ ansible_test.environment }}"
tasks: tasks:
- block: - module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block:
- set_fact: - set_fact:
instance_id: '{{ resource_prefix }}-mariadb' instance_id: '{{ resource_prefix }}-mariadb'
@ -17,15 +23,6 @@
# Create new host, add it to inventory and then terminate it without updating the cache # Create new host, add it to inventory and then terminate it without updating the cache
- name: set connection information for all tasks
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
no_log: yes
- name: create minimal mariadb instance in default VPC and default subnet group - name: create minimal mariadb instance in default VPC and default subnet group
rds_instance: rds_instance:
state: present state: present
@ -37,7 +34,6 @@
master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}' master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}'
tags: tags:
workload_type: other workload_type: other
<<: *aws_connection_info
register: setup_instance register: setup_instance
- meta: refresh_inventory - meta: refresh_inventory
@ -54,6 +50,5 @@
engine: mariadb engine: mariadb
skip_final_snapshot: yes skip_final_snapshot: yes
instance_id: '{{ instance_id }}' instance_id: '{{ instance_id }}'
<<: *aws_connection_info
ignore_errors: yes ignore_errors: yes
when: setup_instance is defined when: setup_instance is defined

View file

@ -5,7 +5,13 @@
environment: "{{ ansible_test.environment }}" environment: "{{ ansible_test.environment }}"
tasks: tasks:
- block: - module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block:
- set_fact: - set_fact:
instance_id: "{{ resource_prefix }}-mariadb" instance_id: "{{ resource_prefix }}-mariadb"
@ -19,15 +25,6 @@
# Create new host, refresh inventory, remove host, refresh inventory # Create new host, refresh inventory, remove host, refresh inventory
- name: set connection information for all tasks
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
no_log: yes
- name: create minimal mariadb instance in default VPC and default subnet group - name: create minimal mariadb instance in default VPC and default subnet group
rds_instance: rds_instance:
state: present state: present
@ -39,7 +36,6 @@
master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}' master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}'
tags: tags:
workload_type: other workload_type: other
<<: *aws_connection_info
register: setup_instance register: setup_instance
- meta: refresh_inventory - meta: refresh_inventory
@ -57,7 +53,6 @@
engine: mariadb engine: mariadb
skip_final_snapshot: yes skip_final_snapshot: yes
instance_id: '{{ instance_id }}' instance_id: '{{ instance_id }}'
<<: *aws_connection_info
- meta: refresh_inventory - meta: refresh_inventory
@ -75,6 +70,5 @@
engine: mariadb engine: mariadb
skip_final_snapshot: yes skip_final_snapshot: yes
instance_id: '{{ instance_id }}' instance_id: '{{ instance_id }}'
<<: *aws_connection_info
ignore_errors: yes ignore_errors: yes
when: setup_instance is defined when: setup_instance is defined

View file

@ -5,22 +5,17 @@
environment: "{{ ansible_test.environment }}" environment: "{{ ansible_test.environment }}"
tasks: tasks:
- block: - module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block:
- set_fact: - set_fact:
instance_id: "{{ resource_prefix }}-mariadb" instance_id: "{{ resource_prefix }}-mariadb"
# Create new host, refresh inventory
- name: set connection information for all tasks
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token }}'
region: '{{ aws_region }}'
no_log: yes
- name: create minimal mariadb instance in default VPC and default subnet group - name: create minimal mariadb instance in default VPC and default subnet group
rds_instance: rds_instance:
state: present state: present
@ -32,20 +27,28 @@
master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}' master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}'
tags: tags:
workload_type: other workload_type: other
<<: *aws_connection_info
register: setup_instance register: setup_instance
- meta: refresh_inventory - meta: refresh_inventory
- debug: var=groups - debug: var=groups
- name: 'generate expected group name based off the db parameter groups'
vars:
parameter_group_name: '{{ setup_instance.db_parameter_groups[0].db_parameter_group_name }}'
set_fact:
parameter_group_key: 'rds_parameter_group_{{ parameter_group_name | replace(".", "_") }}'
- name: assert the keyed groups from constructed config were added to inventory - name: assert the keyed groups from constructed config were added to inventory
assert: assert:
that: that:
# There are 6 groups: all, ungrouped, aws_rds, tag keyed group, engine keyed group, parameter group keyed group # There are 6 groups: all, ungrouped, aws_rds, tag keyed group, engine keyed group, parameter group keyed group
- "groups | length == 6" - "groups | length == 6"
- groups.tag_workload_type_other - '"all" in groups'
- groups.rds_mariadb - '"ungrouped" in groups'
- groups.rds_parameter_group_default_mariadb10_3 - '"aws_rds" in groups'
- '"tag_workload_type_other" in groups'
- '"rds_mariadb" in groups'
- 'parameter_group_key in groups'
always: always:
@ -55,6 +58,5 @@
engine: mariadb engine: mariadb
skip_final_snapshot: yes skip_final_snapshot: yes
instance_id: '{{ instance_id }}' instance_id: '{{ instance_id }}'
<<: *aws_connection_info
ignore_errors: yes ignore_errors: yes
when: setup_instance is defined when: setup_instance is defined

View file

@ -1,4 +1,10 @@
- name: test updating inventory - name: test updating inventory
module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block: block:
- set_fact: - set_fact:
instance_id: "{{ resource_prefix }}update" instance_id: "{{ resource_prefix }}update"
@ -9,15 +15,6 @@
- "'aws_rds' in groups" - "'aws_rds' in groups"
- "not groups.aws_rds" - "not groups.aws_rds"
- name: set connection information for all tasks
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes
- name: create minimal mariadb instance in default VPC and default subnet group - name: create minimal mariadb instance in default VPC and default subnet group
rds_instance: rds_instance:
state: present state: present
@ -29,7 +26,6 @@
master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}' master_user_password: 'password-{{ resource_prefix | regex_findall(".{8}$") | first }}'
tags: tags:
workload_type: other workload_type: other
<<: *aws_connection_info
register: setup_instance register: setup_instance
- meta: refresh_inventory - meta: refresh_inventory
@ -47,7 +43,6 @@
engine: mariadb engine: mariadb
skip_final_snapshot: yes skip_final_snapshot: yes
instance_id: ansible-rds-mariadb-example instance_id: ansible-rds-mariadb-example
<<: *aws_connection_info
- meta: refresh_inventory - meta: refresh_inventory
@ -65,6 +60,5 @@
engine: mariadb engine: mariadb
skip_final_snapshot: yes skip_final_snapshot: yes
instance_id: ansible-rds-mariadb-example instance_id: ansible-rds-mariadb-example
<<: *aws_connection_info
ignore_errors: yes ignore_errors: yes
when: setup_instance is defined when: setup_instance is defined

View file

@ -20,7 +20,7 @@ ansible-playbook playbooks/create_inventory_config.yml "$@"
ansible-playbook playbooks/test_populating_inventory.yml "$@" ansible-playbook playbooks/test_populating_inventory.yml "$@"
# generate inventory config with caching and test using it # generate inventory config with caching and test using it
ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_cache.yml'" "$@" ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_cache.j2'" "$@"
ansible-playbook playbooks/populate_cache.yml "$@" ansible-playbook playbooks/populate_cache.yml "$@"
ansible-playbook playbooks/test_inventory_cache.yml "$@" ansible-playbook playbooks/test_inventory_cache.yml "$@"
@ -28,7 +28,7 @@ ansible-playbook playbooks/test_inventory_cache.yml "$@"
rm -r aws_rds_cache_dir/ rm -r aws_rds_cache_dir/
# generate inventory config with constructed features and test using it # generate inventory config with constructed features and test using it
ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_constructed.yml'" "$@" ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_constructed.j2'" "$@"
ansible-playbook playbooks/test_populating_inventory_with_constructed.yml "$@" ansible-playbook playbooks/test_populating_inventory_with_constructed.yml "$@"
# cleanup inventory config # cleanup inventory config

View file

@ -1,7 +1,9 @@
plugin: aws_rds plugin: aws_rds
aws_access_key_id: '{{ aws_access_key }}' aws_access_key_id: '{{ aws_access_key }}'
aws_secret_access_key: '{{ aws_secret_key }}' aws_secret_access_key: '{{ aws_secret_key }}'
{% if security_token | default(false) %}
aws_security_token: '{{ security_token }}' aws_security_token: '{{ security_token }}'
{% endif %}
regions: regions:
- '{{ aws_region }}' - '{{ aws_region }}'
filters: filters:

View file

@ -4,7 +4,9 @@ cache_plugin: jsonfile
cache_connection: aws_rds_cache_dir cache_connection: aws_rds_cache_dir
aws_access_key_id: '{{ aws_access_key }}' aws_access_key_id: '{{ aws_access_key }}'
aws_secret_access_key: '{{ aws_secret_key }}' aws_secret_access_key: '{{ aws_secret_key }}'
{% if security_token | default(false) %}
aws_security_token: '{{ security_token }}' aws_security_token: '{{ security_token }}'
{% endif %}
regions: regions:
- '{{ aws_region }}' - '{{ aws_region }}'
filters: filters:

View file

@ -1,7 +1,9 @@
plugin: aws_rds plugin: aws_rds
aws_access_key_id: '{{ aws_access_key }}' aws_access_key_id: '{{ aws_access_key }}'
aws_secret_access_key: '{{ aws_secret_key }}' aws_secret_access_key: '{{ aws_secret_key }}'
{% if security_token | default(false) %}
aws_security_token: '{{ security_token }}' aws_security_token: '{{ security_token }}'
{% endif %}
regions: regions:
- '{{ aws_region }}' - '{{ aws_region }}'
keyed_groups: keyed_groups: