Skip to content

KeyError in rds_instance module on MonitoringRoleARN when modifying instance #51772

Description

@nethershaw
SUMMARY

When using the rds_instance module to modify an existing RDS instance such that the module parameter monitoring_interval is changed from a 0 or absent value and the parameter monitoring_role_arn is set to a valid IAM Role ARN, a traceback is thrown indicating a KeyError on the key MonitoringRoleArn. The error does not occur when creating a new RDS instance with otherwise identical parameters, and it does not occur if including the Enhanced Monitoring parameters would not cause a change to the targeted instance.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Module: rds_instance

ANSIBLE VERSION
ansible 2.7.6
  config file = /home/mavaug/Documents/git/sasia/ansible.cfg
  configured module search path = [u'/home/mavaug/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib64/python2.7/site-packages/ansible
  executable location = /usr/lib/python-exec/python2.7/ansible
  python version = 2.7.15 (default, Sep 17 2018, 11:47:40) [GCC 7.3.0]
CONFIGURATION
ANSIBLE_PIPELINING(/home/mavaug/Documents/git/sasia/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/home/mavaug/Documents/git/sasia/ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=1800s
ANSIBLE_SSH_CONTROL_PATH(/home/mavaug/Documents/git/sasia/ansible.cfg) = %(directory)s/%%h-%%p-%%r
ANSIBLE_SSH_CONTROL_PATH_DIR(/home/mavaug/Documents/git/sasia/ansible.cfg) = /tmp/.ansible/cp
CACHE_PLUGIN(/home/mavaug/Documents/git/sasia/ansible.cfg) = redis
COMMAND_WARNINGS(/home/mavaug/Documents/git/sasia/ansible.cfg) = True
DEFAULT_FORKS(/home/mavaug/Documents/git/sasia/ansible.cfg) = 16
DEFAULT_GATHERING(/home/mavaug/Documents/git/sasia/ansible.cfg) = implicit
DEFAULT_GATHER_SUBSET(/home/mavaug/Documents/git/sasia/ansible.cfg) = all
DEFAULT_GATHER_TIMEOUT(/home/mavaug/Documents/git/sasia/ansible.cfg) = 30
DEFAULT_HOST_LIST(/home/mavaug/Documents/git/sasia/ansible.cfg) = [u'/home/mavaug/Documents/git/sasia/inventory/ec2.py']
DEFAULT_LOG_PATH(/home/mavaug/Documents/git/sasia/ansible.cfg) = /var/log/ansible.log
DEFAULT_MANAGED_STR(/home/mavaug/Documents/git/sasia/ansible.cfg) = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
DEFAULT_REMOTE_USER(/home/mavaug/Documents/git/sasia/ansible.cfg) = root
DEFAULT_TRANSPORT(/home/mavaug/Documents/git/sasia/ansible.cfg) = ssh
DEFAULT_VAULT_PASSWORD_FILE(/home/mavaug/Documents/git/sasia/ansible.cfg) = /home/mavaug/.ansible.vault_pass
DEPRECATION_WARNINGS(/home/mavaug/Documents/git/sasia/ansible.cfg) = True
HOST_KEY_CHECKING(/home/mavaug/Documents/git/sasia/ansible.cfg) = False
SYSTEM_WARNINGS(/home/mavaug/Documents/git/sasia/ansible.cfg) = True
OS / ENVIRONMENT
  • Gentoo Linux
  • Python 2.7.15
  • boto 2.49.0
  • boto3 1.9.87
  • botocore 1.12.87
STEPS TO REPRODUCE

Write a playbook containing four tasks:

  • Create a control RDS instance using the rds_instance module, including the monitoring_interval and monitoring_role_arn parameters. Verify in the RDS Console that the instance is created and Enhanced Monitoring is enabled, validating that the Enhanced Monitoring parameters function correctly in the case of instance creation.
  • Duplicate the first task and all of its parameters, targeting the same control instance. Verify in the RDS Console that the control instance is unchanged, and that Ansible agrees no change was made, validating that the Enhanced Monitoring parameters function correctly in the case that they cause no modifications to an existing instance.
  • Create an experimental RDS instance using the rds_instance module, with the same parameters as the control instance, but while omitting the monitoring_interval and monitoring_role_arn parameters. Verify in the RDS Console that the instance is created and Enhanced Monitoring is disabled.
  • Modify the first RDS instance by running the rds_instance module against it a second time, differing only by the addition of the monitoring_interval and monitoring_role_arn parameters. Verify in the RDS Console whether the instance has been modified and whether its Enhanced Monitoring configuration is enabled.
---
- name: issue reproduction
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
    - name: create a control RDS instance, with Enhanced Monitoring
      rds_instance:
        state: present
        allocated_storage: 10
        db_instance_identifier: test-control
        db_instance_class: db.t2.large
        engine: mysql
        master_user_password: badpassword
        master_username: badusername
        monitoring_interval: 60
        monitoring_role_arn: arn:aws:iam::123456789012:role/rds-monitoring-role
        region: us-west-2
        wait: true
      tags:
        - control

    - name: make no modifications to the control RDS instance (no-op)
      rds_instance:
        state: present
        allocated_storage: 10
        db_instance_identifier: test-control
        db_instance_class: db.t2.large
        engine: mysql
        master_user_password: badpassword
        master_username: badusername
        monitoring_interval: 60
        monitoring_role_arn: arn:aws:iam::123456789012:role/rds-monitoring-role
        region: us-west-2
        wait: true
      tags:
        - control

    - name: create an experimental RDS instance, without Enhanced Monitoring
      rds_instance:
        state: present
        allocated_storage: 10
        db_instance_identifier: test-experimental
        db_instance_class: db.t2.large
        engine: mysql
        master_user_password: badpassword
        master_username: badusername
        region: us-west-2
        wait: true
      tags:
        - experimental

    - name: modify the experimental RDS instance, adding Enhanced Monitoring
      rds_instance:
        state: present
        allocated_storage: 10
        db_instance_identifier: test-experimental
        db_instance_class: db.t2.large
        engine: mysql
        master_user_password: badpassword
        master_username: badusername
        monitoring_interval: 60
        monitoring_role_arn: arn:aws:iam::123456789012:role/rds-monitoring-role
        region: us-west-2
        wait: true
      tags:
        - experimental
...
EXPECTED RESULTS

All four tasks should succeed. Ultimately there should be two databases, both identical aside from their names, and both with Enhanced Monitoring enabled.

ACTUAL RESULTS

The first three tasks succeed as expected. The fourth task prints an unexpected traceback and fails. The experimental instance is not modified, and Enhanced Monitoring is not enabled on the experimental instance.

TASK [modify the experimental RDS instance, adding Enhanced Monitoring] ***
task path: /home/mavaug/Documents/git/sasia/repro.yml:53
Using module file /usr/lib64/python2.7/site-packages/ansible/modules/cloud/amazon/rds_instance.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: mavaug
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2.7 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "<stdin>", line 113, in <module>
  File "<stdin>", line 105, in _ansiballz_main
  File "<stdin>", line 48, in invoke_module
  File "/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py", line 1157, in <module>
  File "/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py", line 1122, in main
  File "/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py", line 780, in get_parameters
  File "/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py", line 804, in get_options_with_changing_values
  File "/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py", line 896, in get_changing_options_with_consistent_keys
KeyError: 'MonitoringRoleArn'

fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 113, in <module>\n  File \"<stdin>\", line 105, in _ansiballz_main\n  File \"<stdin>\", line 48, in invoke_module\n  File \"/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py\", line 1157, in <module>\n  File \"/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py\", line 1122, in main\n  File \"/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py\", line 780, in get_parameters\n  File \"/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py\", line 804, in get_options_with_changing_values\n  File \"/tmp/ansible_rds_instance_payload_9qvZmn/__main__.py\", line 896, in get_changing_options_with_consistent_keys\nKeyError: 'MonitoringRoleArn'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects_2.7This issue/PR affects Ansible v2.7bugThis issue/PR relates to a bug.moduleThis issue/PR relates to a module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions