Skip to content

Commit

Permalink
Delete role before creating it again.
Browse files Browse the repository at this point in the history
  • Loading branch information
fridim committed Oct 8, 2024
1 parent d1940a5 commit bdd2ff5
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions playbooks/roles/infra-aws-sandbox/tasks/iam.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
---
- name: Delete IAM role Cloudformation stack
cloudformation:
profile: "{{ account_profile }}"
region: "{{ aws_region }}"
stack_name: roles
state: absent

- name: Create IAM role using Cloudformation
cloudformation:
profile: "{{ account_profile }}"
template_body: "{{ lookup('file', 'CF-IAM.json') }}"
region: "{{ aws_region }}"
stack_name: roles
register: _cfiamrole
until: _cfiamrole is succeeded
delay: 60
retries: 5
register: r_cf

- when: r_cf is failed
block:
- name: Delete IAM role Cloudformation stack
cloudformation:
profile: "{{ account_profile }}"
region: "{{ aws_region }}"
stack_name: roles
state: absent

- name: Delete the config-rule-role role
iam_role:
profile: "{{ account_profile }}"
name: config-rule-role
state: absent

- name: Retry create IAM role using Cloudformation
cloudformation:
profile: "{{ account_profile }}"
template_body: "{{ lookup('file', 'CF-IAM.json') }}"
region: "{{ aws_region }}"
stack_name: roles

0 comments on commit bdd2ff5

Please sign in to comment.