2014-02-24 19:37:23 +00:00
|
|
|
---
|
|
|
|
# A Note about ec2 environment variable name preference:
|
|
|
|
# - EC2_URL -> AWS_URL
|
|
|
|
# - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY
|
|
|
|
# - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY
|
|
|
|
# - EC2_REGION -> AWS_REGION
|
|
|
|
#
|
|
|
|
# TODO - name: test 'validate_certs' parameter
|
2017-12-08 20:34:46 +00:00
|
|
|
# TODO - name: test creating key pair with another_key_material with force=yes
|
2014-02-24 19:37:23 +00:00
|
|
|
# ============================================================
|
|
|
|
# - include: ../../setup_ec2/tasks/common.yml module_name=ec2_key
|
|
|
|
|
2017-05-03 00:20:39 +00:00
|
|
|
- block:
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test with no parameters
|
|
|
|
ec2_key:
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert failure when called with no parameters
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
|
|
|
- 'result.msg == "missing required arguments: name"'
|
|
|
|
|
|
|
|
# ============================================================
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: test removing a non-existent key pair
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_key:
|
|
|
|
name='{{ec2_key_name}}'
|
|
|
|
ec2_region={{ec2_region}}
|
|
|
|
ec2_access_key={{ec2_access_key}}
|
|
|
|
ec2_secret_key={{ec2_secret_key}}
|
|
|
|
security_token={{security_token}}
|
|
|
|
state=absent
|
|
|
|
register: result
|
|
|
|
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: assert removing a non-existent key pair
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'not result.changed'
|
|
|
|
|
2017-05-03 00:20:39 +00:00
|
|
|
# ============================================================
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: test creating a new key pair
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_key:
|
|
|
|
name='{{ec2_key_name}}'
|
|
|
|
ec2_region={{ec2_region}}
|
|
|
|
ec2_access_key={{ec2_access_key}}
|
|
|
|
ec2_secret_key={{ec2_secret_key}}
|
|
|
|
security_token={{security_token}}
|
|
|
|
state=present
|
|
|
|
register: result
|
|
|
|
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: assert creating a new key pair
|
2017-05-03 00:20:39 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- '"key" in result'
|
|
|
|
- '"name" in result.key'
|
|
|
|
- '"fingerprint" in result.key'
|
|
|
|
- '"private_key" in result.key'
|
|
|
|
- 'result.key.name == "{{ec2_key_name}}"'
|
|
|
|
|
|
|
|
# ============================================================
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: test removing an existent key
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_key:
|
|
|
|
name='{{ec2_key_name}}'
|
|
|
|
state=absent
|
|
|
|
environment:
|
|
|
|
EC2_REGION: '{{ec2_region}}'
|
|
|
|
EC2_ACCESS_KEY: '{{ec2_access_key}}'
|
|
|
|
EC2_SECRET_KEY: '{{ec2_secret_key}}'
|
|
|
|
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
|
|
|
|
register: result
|
|
|
|
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: assert removing an existent key
|
2017-05-03 00:20:39 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- '"key" in result'
|
|
|
|
- 'result.key == None'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test state=present with key_material
|
|
|
|
ec2_key:
|
|
|
|
name='{{ec2_key_name}}'
|
|
|
|
key_material='{{key_material}}'
|
|
|
|
state=present
|
|
|
|
environment:
|
|
|
|
EC2_REGION: '{{ec2_region}}'
|
|
|
|
EC2_ACCESS_KEY: '{{ec2_access_key}}'
|
|
|
|
EC2_SECRET_KEY: '{{ec2_secret_key}}'
|
|
|
|
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=present with key_material
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed == True'
|
|
|
|
- '"key" in result'
|
|
|
|
- '"name" in result.key'
|
|
|
|
- '"fingerprint" in result.key'
|
|
|
|
- '"private_key" not in result.key'
|
2017-12-08 20:34:46 +00:00
|
|
|
- 'result.key.name == "{{ec2_key_name}}"'
|
2017-11-14 04:40:55 +00:00
|
|
|
- 'result.key.fingerprint == "{{fingerprint}}"'
|
2017-05-03 00:20:39 +00:00
|
|
|
|
2017-11-15 12:53:41 +00:00
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
- name: test force=no with another_key_material (expect changed=false)
|
|
|
|
ec2_key:
|
|
|
|
name: '{{ ec2_key_name }}'
|
|
|
|
ec2_region: '{{ ec2_region }}'
|
|
|
|
ec2_access_key: '{{ ec2_access_key }}'
|
|
|
|
ec2_secret_key: '{{ ec2_secret_key }}'
|
|
|
|
security_token: '{{ security_token }}'
|
|
|
|
key_material: '{{ another_key_material }}'
|
|
|
|
force: no
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert force=no with another_key_material (expect changed=false)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'not result.changed'
|
|
|
|
- 'result.key.fingerprint == "{{ fingerprint }}"'
|
|
|
|
|
2017-05-03 00:20:39 +00:00
|
|
|
# ============================================================
|
2017-12-08 20:34:46 +00:00
|
|
|
|
|
|
|
- name: test updating a key pair using another_key_material (expect changed=True)
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_key:
|
2017-12-08 20:34:46 +00:00
|
|
|
name: '{{ ec2_key_name }}'
|
|
|
|
ec2_region: '{{ ec2_region }}'
|
|
|
|
ec2_access_key: '{{ ec2_access_key }}'
|
|
|
|
ec2_secret_key: '{{ ec2_secret_key }}'
|
|
|
|
security_token: '{{ security_token }}'
|
|
|
|
key_material: '{{ another_key_material }}'
|
2017-05-03 00:20:39 +00:00
|
|
|
register: result
|
|
|
|
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: assert updating a key pair using another_key_material (expect changed=True)
|
2017-05-03 00:20:39 +00:00
|
|
|
assert:
|
|
|
|
that:
|
2017-12-08 20:34:46 +00:00
|
|
|
- 'result.changed'
|
|
|
|
- 'result.key.fingerprint != "{{ fingerprint }}"'
|
|
|
|
|
|
|
|
# ============================================================
|
2017-05-03 00:20:39 +00:00
|
|
|
|
|
|
|
always:
|
|
|
|
|
|
|
|
# ============================================================
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: test state=absent (expect changed=true)
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_key:
|
|
|
|
name='{{ec2_key_name}}'
|
|
|
|
ec2_region='{{ec2_region}}'
|
|
|
|
ec2_access_key='{{ec2_access_key}}'
|
|
|
|
ec2_secret_key='{{ec2_secret_key}}'
|
|
|
|
security_token='{{security_token}}'
|
|
|
|
state=absent
|
|
|
|
register: result
|
|
|
|
|
2017-12-08 20:34:46 +00:00
|
|
|
- name: assert state=absent with key_material (expect changed=true)
|
2017-05-03 00:20:39 +00:00
|
|
|
assert:
|
|
|
|
that:
|
2017-12-08 20:34:46 +00:00
|
|
|
- 'result.changed'
|
2017-05-03 00:20:39 +00:00
|
|
|
- '"key" in result'
|
|
|
|
- 'result.key == None'
|