2017-01-17 19:45:43 +00:00
|
|
|
---
|
|
|
|
- set_fact:
|
|
|
|
ecr_name: 'ecr-test-{{ ansible_date_time.epoch }}'
|
|
|
|
|
|
|
|
- block:
|
2017-05-03 00:20:39 +00:00
|
|
|
|
2017-01-17 19:45:43 +00:00
|
|
|
- name: When creating with check mode
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: it should skip, change and create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is skipped
|
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When specifying a registry that is inaccessible
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
registry_id: 999999999999
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: it should fail with an AccessDeniedException
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is failed
|
2017-01-17 19:45:43 +00:00
|
|
|
- '"AccessDeniedException" in result.msg'
|
|
|
|
|
|
|
|
|
|
|
|
- name: When creating a repository
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should change and create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When creating a repository that already exists in check mode
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: it should not skip, should not change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is not skipped
|
|
|
|
- result is not changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When creating a repository that already exists
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should not change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is not changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When in check mode, and deleting a policy that does not exists
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
delete_policy: yes
|
|
|
|
register: result
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: it should not skip and not change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is not skipped
|
|
|
|
- result is not changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When in check mode, setting policy on a repository that has no policy
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
policy: '{{ policy }}'
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: it should skip, change and not create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is skipped
|
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- not result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When setting policy on a repository that has no policy
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
policy: '{{ policy }}'
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should change and not create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- not result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When in check mode, and deleting a policy that exists
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
delete_policy: yes
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: it should skip, change but not create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is skipped
|
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- not result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When deleting a policy that exists
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
delete_policy: yes
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should change and not create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- not result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When setting a policy as a string
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
policy: '{{ policy | to_json }}'
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should change and not create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- not result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When setting a policy to its current value
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
policy: '{{ policy }}'
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should not change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is not changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When omitting policy on a repository that has a policy
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should not change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is not changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When specifying both policy and delete_policy
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
policy: '{{ policy }}'
|
|
|
|
delete_policy: yes
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: it should fail
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is failed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When specifying invalid JSON for policy
|
|
|
|
ecs_ecr:
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
policy_text: "Ceci n'est pas une JSON"
|
2017-05-03 00:20:39 +00:00
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: it should fail
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is failed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When in check mode, deleting a policy that exists
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
state: absent
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: it should skip, change and not create
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is skipped
|
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
- not result.created
|
|
|
|
|
|
|
|
|
|
|
|
- name: When deleting a policy that exists
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
state: absent
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When in check mode, deleting a policy that does not exist
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
state: absent
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: it should not change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is not skipped
|
|
|
|
- result is not changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: When deleting a policy that does not exist
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
state: absent
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
2017-01-17 19:45:43 +00:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: it should not change
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- result is not changed
|
2017-01-17 19:45:43 +00:00
|
|
|
|
|
|
|
always:
|
2017-05-03 00:20:39 +00:00
|
|
|
|
2017-01-17 19:45:43 +00:00
|
|
|
- name: Delete lingering ECR repository
|
2017-05-03 00:20:39 +00:00
|
|
|
ecs_ecr:
|
|
|
|
name: '{{ ecr_name }}'
|
|
|
|
region: '{{ ec2_region }}'
|
|
|
|
state: absent
|
|
|
|
ec2_access_key: '{{ec2_access_key}}'
|
|
|
|
ec2_secret_key: '{{ec2_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|