Skip to content

Commit

Permalink
Ansible-lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hakbailey committed Jul 11, 2023
1 parent 6e13559 commit 1cb6fda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions roles/backup_create_plan/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
block:
- name: Fail when plan variables are not defined
ansible.builtin.fail:
msg: "Required variable {{item}} has not been defined"
msg: "Required variable {{ item }} has not been defined"
when: vars[item] is undefined
loop:
- plan_name
Expand All @@ -21,17 +21,17 @@
backup_vault_name: "{{ vault_name }}"
encryption_key_arn: "{{ vault_encryption_key_arn | default(omit) }}"
tags: "{{ vault_tags | default(omit) }}"
register: backup_vault_result
register: backup_create_plan_backup_vault_result

- name: Verify that vault has been created/updated
ansible.builtin.debug:
msg: Vault '{{ vault_name }}' successfully created/updated.
when: backup_vault_result is changed
when: backup_create_plan_backup_vault_result is changed

- name: Verify that vault already exists
ansible.builtin.debug:
msg: Vault '{{ vault_name }}' exists, no updates needed.
when: backup_vault_result is not changed
when: backup_create_plan_backup_vault_result is not changed

- name: Create or update backup plan
amazon.aws.backup_plan:
Expand All @@ -40,14 +40,14 @@
rules: "{{ plan_rules }}"
advanced_backup_settings: "{{ plan_windows_vss_settings | default(omit) }}"
tags: "{{ plan_tags | default(omit) }}"
register: backup_plan_result
register: backup_create_plan_backup_plan_result

- name: Verify that plan has been created/updated
ansible.builtin.debug:
msg: Plan '{{ plan_name }}' successfully created/updated.
when: backup_plan_result is changed
when: backup_create_plan_backup_plan_result is changed

- name: Verify that plan already exists
ansible.builtin.debug:
msg: Plan '{{ plan_name }}' exists, no updates needed.
when: backup_plan_result is not changed
when: backup_create_plan_backup_plan_result is not changed
20 changes: 10 additions & 10 deletions roles/backup_select_resources/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
amazon.aws.backup_plan_info:
backup_plan_names:
- "{{ plan_name }}"
register: backup_plan_info
register: backup_select_resources_backup_plan_info

- name: Fail when backup plan does not exist
ansible.builtin.fail:
msg: Backup plan {{ plan_name }} does not exist, please create or confirm plan name is correct.
when: backup_plan_info.backup_plans | length == 0
when: backup_select_resources_backup_plan_info.backup_plans | length == 0

- name: Get provided IAM role info
community.aws.iam_role_info:
name: "{{ backup_role_name }}"
register: role_info
register: backup_select_resources_role_info

- name: Create new role when IAM role does not exist
block:
- name: Create role
when: role_info.iam_roles | length == 0
when: backup_select_resources_role_info.iam_roles | length == 0
community.aws.iam_role:
name: "{{ backup_role_name }}"
state: present
Expand All @@ -42,34 +42,34 @@
managed_policy:
- arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup
wait: true
register: new_role_info
register: backup_select_resources_new_role_info

- name: Wait for role to be created
ansible.builtin.pause:
seconds: 8

- name: Set backup role ARN
ansible.builtin.set_fact:
backup_role_arn: "{{ role_info.iam_roles[0].arn if new_role_info is skipped else new_role_info.arn }}"
backup_select_resources_backup_role_arn: "{{ backup_select_resources_role_info.iam_roles[0].arn if backup_select_resources_new_role_info is skipped else backup_select_resources_new_role_info.arn }}"

- name: Create or update backup selection
amazon.aws.backup_selection:
state: present
backup_plan_name: "{{ plan_name }}"
selection_name: "{{ selection_name }}"
iam_role_arn: "{{ backup_role_arn }}"
iam_role_arn: "{{ backup_select_resources_backup_role_arn }}"
resources: "{{ selection_resources }}"
list_of_tags: "{{ selection_tags | default(omit) }}"
not_resources: "{{ selection_excluded_resources | default(omit) }}"
conditions: "{{ selection_conditions | default(omit) }}"
register: selection_result
register: backup_select_resources_selection_result

- name: Verify that selection has been created/updated
ansible.builtin.debug:
msg: Backup selection '{{ selection_name }}' successfully created/updated.
when: selection_result is changed
when: backup_select_resources_selection_result is changed

- name: Verify that selection already exists
ansible.builtin.debug:
msg: Backup selection '{{ selection_name }}' exists, no updates needed.
when: selection_result is not changed
when: backup_select_resources_selection_result is not changed

0 comments on commit 1cb6fda

Please sign in to comment.