boto/ansible ec2_vol module encrypted attribute issue
t-readyroc opened this issue · comments
(had initially erroneously posted here)
OS X
Ansible 2.5
Python: 2.7
Boto: 2.48
Attempts to use this module to both create and delete ec2 volumes fails with the following output:
AttributeError: 'Volume' object has no attribute 'encrypted'
Code:
ec2_vol:
region: us-east-1
aws_access_key: <redacted>
aws_secret_key: <redacted>
instance: "{{ instanceid }}"
volume_size: "{{ size }}"
volume_type: gp2
device_name: /dev/xvdk
tags: {'Name': "{{ instancename }}:{{ target }}"}
when: action == "mount"
This error occurs even when explicitly defining an "encrypted: no" attribute in the task (the attribute is optional). The parameters of boto "create_volume" also list "encrypted" as optional, though the error would seem to say otherwise.
We also had this problem and developed the following workaround by calling AWS EC2 CLI directly, bypassing the ec2_vol
module. Note that the returned JSON is slightly different from what the ec2_vol
returns, so you need to adjust any subsequent steps accordingly.
#
# This ansible ec2_vol: usage was replaced 2018-05-17 because it was buggy because it
# complained: 'AttributeError: 'Volume' object has no attribute 'encrypted'\r\n"'
#
# - name: List EC2 EBS volumes
# when: ansible_ec2_instance_id is defined
# ec2_vol:
# aws_access_key: "{{ ec2_access_key }}"
# aws_secret_key: "{{ ec2_secret_key }}"
# instance: "{{ ansible_ec2_instance_id }}"
# region: "{{ ec2_region }}"
# state: list
# register: aws_ec2_ebs
- name: List EC2 EBS volumes
when: ansible_ec2_instance_id is defined
local_action:
module: shell
_raw_params: >-
aws ec2 describe-volumes --output json
--filters Name=attachment.instance-id,Values={{ ansible_ec2_instance_id }}
register: aws_ec2_ebs
- name: Interpret the JSON response
set_fact:
aws_ec2_ebs: "{{ aws_ec2_ebs.stdout | from_json }}"