Skip to content

Commit

Permalink
A round of sanity fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <abuzachis@redhat.com>
  • Loading branch information
alinabuzachis committed Jul 5, 2023
1 parent d6e2af7 commit dd571bd
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 188 deletions.
2 changes: 1 addition & 1 deletion roles/aws_setup_credentials/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Define intial value for credentials
ansible.builtin.set_fact:
aws_role_credentials: {}
aws_setup_credentials__aws_role_credentials: {}
- name: Create auth credentials
ansible.builtin.include_tasks: read_option.yml
with_dict: "{{ aws_connection_env }}"
18 changes: 9 additions & 9 deletions roles/aws_setup_credentials/tasks/read_option.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
- name: Set 'option_key' and 'option_value' from Environment
ansible.builtin.set_fact:
option_key: "{{ ('dest' in item.value) | ternary(item.value.dest, item.key) }}"
option_value: "{{ lookup('vars', item.key, default='') }}"
aws_setup_credentials__option_key: "{{ ('dest' in item.value) | ternary(item.value.dest, item.key) }}"
aws_setup_credentials__option_value: "{{ lookup('vars', item.key, default='') }}"

- name: Combine user-defined variable
ansible.builtin.set_fact:
aws_role_credentials: "{{ aws_role_credentials | combine({option_key: option_value}) }}"
when: option_value | length > 0
aws_setup_credentials__aws_role_credentials: "{{ aws_setup_credentials__aws_role_credentials | combine({aws_setup_credentials__option_key: aws_setup_credentials__option_value}) }}"
when: aws_setup_credentials__option_value | length > 0

- name: Read value from Environment
when: option_value | length == 0
when: aws_setup_credentials__option_value | length == 0
block:
- name: Set 'env_values' variable
ansible.builtin.set_fact:
env_values: []
aws_setup_credentials__env_values: []
- name: Set 'env_values' from Environment
ansible.builtin.set_fact:
env_values: "{{ env_values + [current_value] }}"
aws_setup_credentials__env_values: "{{ aws_setup_credentials__env_values + [current_value] }}"
with_items: "{{ ('env' in item.value) | ternary(item.value.env, []) }}"
when: current_value | length > 0
loop_control:
Expand All @@ -27,5 +27,5 @@

- name: Combine with environment-defined variable
ansible.builtin.set_fact:
aws_role_credentials: "{{ aws_role_credentials | combine({option_key: env_values[0]}) }}"
when: env_values | length > 0
aws_setup_credentials__aws_role_credentials: "{{ aws_setup_credentials__aws_role_credentials | combine({aws_setup_credentials__option_key: aws_setup_credentials__env_values[0]}) }}"
when: aws_setup_credentials__env_values | length > 0
2 changes: 1 addition & 1 deletion roles/connectivity_troubleshooter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Authentication against AWS is managed by the `aws_setup_credentials` role.
It also requires the folllowing roles:
- cloud.aws_troubleshooting.connectivity_troubleshooter_validate
- cloud.aws_troubleshooting.connectivity_troubleshooter_igw
- cloud.aws_troubleshooting.connectivity_troubleshooter_local
- cloud.aws_troubleshooting.connectivity_troubleshooter_local
- cloud.aws_troubleshooting.connectivity_troubleshooter_nat
- cloud.aws_troubleshooting.connectivity_troubleshooter_peering

Expand Down
14 changes: 7 additions & 7 deletions roles/connectivity_troubleshooter/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# tasks file for roles/connectivity_troubleshooter
- name: Run 'connectivity_troubleshooter'
module_defaults:
group/aws: "{{ aws_role_credentials }}"
group/aws: "{{ aws_setup_credentials__aws_role_credentials }}"

block:
- name: Include 'connectivity_troubleshooter_validate' role
Expand All @@ -16,8 +16,8 @@

- name: Fail when next hop type is not supported by this role
ansible.builtin.fail:
msg: Next hop type '{{ next_hop }}' is not supported by this role
when: next_hop != 'local' and not next_hop.startswith('nat-') and not next_hop.startswith('igw-') and not next_hop.startswith('pcx-')
msg: Next hop type '{{ connectivity_troubleshooter_validate__next_hop }}' is not supported by this role
when: connectivity_troubleshooter_validate__next_hop != 'local' and not connectivity_troubleshooter_validate__next_hop.startswith('nat-') and not connectivity_troubleshooter_validate__next_hop.startswith('igw-') and not connectivity_troubleshooter_validate__next_hop.startswith('pcx-')

- name: Include 'connectivity_troubleshooter_local' role
ansible.builtin.include_role:
Expand All @@ -28,7 +28,7 @@
connectivity_troubleshooter_local_source_ip: "{{ connectivity_troubleshooter_source_ip }}"
connectivity_troubleshooter_local_destination_vpc: "{{ connectivity_troubleshooter_destination_vpc }}"
connectivity_troubleshooter_local_source_port_range: "{{ connectivity_troubleshooter_source_port_range }}"
when: "'local' == next_hop"
when: "'local' == connectivity_troubleshooter_validate__next_hop"

- name: Include 'connectivity_troubleshooter_igw' role
ansible.builtin.include_role:
Expand All @@ -40,7 +40,7 @@
connectivity_troubleshooter_igw_destination_vpc: "{{ connectivity_troubleshooter_destination_vpc }}"
connectivity_troubleshooter_igw_source_vpc: "{{ connectivity_troubleshooter_source_vpc }}"
connectivity_troubleshooter_igw_source_port_range: "{{ connectivity_troubleshooter_source_port_range }}"
when: "'igw-' in next_hop"
when: "'igw-' in connectivity_troubleshooter_validate__next_hop"

- name: Include 'connectivity_troubleshooter_nat' role
ansible.builtin.include_role:
Expand All @@ -50,7 +50,7 @@
connectivity_troubleshooter_nat_destination_port: "{{ connectivity_troubleshooter_destination_port }}"
connectivity_troubleshooter_nat_source_ip: "{{ connectivity_troubleshooter_source_ip }}"
connectivity_troubleshooter_nat_source_port_range: "{{ connectivity_troubleshooter_source_port_range }}"
when: "'nat-' in next_hop"
when: "'nat-' in connectivity_troubleshooter_validate__next_hop"

- name: Include 'connectivity_troubleshooter_peering' role
ansible.builtin.include_role:
Expand All @@ -61,4 +61,4 @@
connectivity_troubleshooter_peering_source_ip: "{{ connectivity_troubleshooter_source_ip }}"
connectivity_troubleshooter_peering_destination_vpc: "{{ connectivity_troubleshooter_destination_vpc }}"
connectivity_troubleshooter_peering_source_vpc: "{{ connectivity_troubleshooter_source_vpc }}"
when: "'pcx-' in next_hop"
when: "'pcx-' in connectivity_troubleshooter_validate__next_hop"
14 changes: 7 additions & 7 deletions roles/connectivity_troubleshooter_igw/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
amazon.aws.ec2_security_group_info:
filters:
group_id: "{{ item }}"
register: __src_security_groups
register: connectivity_troubleshooter_igw__src_security_groups
with_items: "{{ src_security_groups }}"

- name: Gather information about Source subnet network ACLs
community.aws.ec2_vpc_nacl_info:
filters:
association.subnet-id:
- "{{ src_subnet_id }}"
register: __src_subnet_nacls
register: connectivity_troubleshooter_igw__src_subnet_nacls

- name: Set 'src_subnet_nacls' variable
ansible.legacy.set_fact:
src_subnet_nacls: "{{ src_subnet_nacls | d([]) + [dict(_keys | zip(_vals))] }}"
loop: "{{ __src_subnet_nacls.nacls }}"
loop: "{{ connectivity_troubleshooter_igw__src_subnet_nacls.nacls }}"
vars:
_keys: "{{ ['egress', 'ingress'] }}"
_vals: "{{ ['egress', 'ingress'] | map('extract', item) }}"

- name: Set 'src_security_groups_info' variable
- name: Set 'connectivity_troubleshooter_igw__src_security_groups_info' variable
ansible.legacy.set_fact:
src_security_groups_info: "{{ __src_security_groups.results | sum(attribute='security_groups', start=[]) }}"
connectivity_troubleshooter_igw__src_security_groups_info: "{{ connectivity_troubleshooter_igw__src_security_groups.results | sum(attribute='security_groups', start=[]) }}"

- name: Evaluate ingress and egress netwok ACLs
cloud.aws_troubleshooting.eval_src_igw_route:
Expand All @@ -41,6 +41,6 @@
dst_ip: "{{ connectivity_troubleshooter_igw_destination_ip }}"
dst_port: "{{ connectivity_troubleshooter_igw_destination_port }}"
src_network_interface: "{{ src_network_interface }}"
src_security_groups_info: "{{ src_security_groups_info }}"
src_security_groups_info: "{{ connectivity_troubleshooter_igw__src_security_groups_info }}"
src_network_acls: "{{ src_subnet_nacls }}"
register: __result_eval_src_igw_route
register: connectivity_troubleshooter_igw__result_eval_src_igw_route
58 changes: 29 additions & 29 deletions roles/connectivity_troubleshooter_local/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@
block:
- name: Fail when next hop type is not supported by this role
ansible.builtin.fail:
msg: Next hop type '{{ next_hop }}' is not supported by this role
when: next_hop != 'local'
msg: Next hop type '{{ connectivity_troubleshooter_validate__next_hop }}' is not supported by this role
when: connectivity_troubleshooter_validate__next_hop != 'local'

- name: Gather information about Destination ENI
amazon.aws.ec2_eni_info:
filters:
addresses.private-ip-address: "{{ connectivity_troubleshooter_local_destination_ip }}"
register: __describe_dst_eni
register: connectivity_troubleshooter_local__describe_dst_eni

- name: Set 'dst_vpc_id', 'dst_subnet_id' and 'dst_security_groups' variables
- name: Set 'connectivity_troubleshooter_local__dst_vpc_id', 'connectivity_troubleshooter_local__dst_subnet_id' and 'connectivity_troubleshooter_local__dst_security_groups' variables
ansible.builtin.set_fact:
dst_vpc_id: "{{ __dst_network_interface_info.vpc_id }}"
dst_subnet_id: "{{ __dst_network_interface_info.subnet_id }}"
dst_security_groups: "{{ __dst_network_interface_info.groups | map(attribute='group_id') | list }}"
connectivity_troubleshooter_local__dst_vpc_id: "{{ __dst_network_interface_info.vpc_id }}"
connectivity_troubleshooter_local__dst_subnet_id: "{{ __dst_network_interface_info.subnet_id }}"
connectivity_troubleshooter_local__dst_security_groups: "{{ __dst_network_interface_info.groups | map(attribute='group_id') | list }}"
vars:
__dst_network_interface_info: "{{ __describe_dst_eni.network_interfaces.0 }}"
__dst_network_interface_info: "{{ connectivity_troubleshooter_local__describe_dst_eni.network_interfaces.0 }}"

- name: Fail when no network interface found
ansible.builtin.fail:
msg: Kindly check the connectivity_troubleshooter_local_destination_ip parameter, no network interface found
when: __describe_dst_eni['network_interfaces'] | length == 0
when: connectivity_troubleshooter_local__describe_dst_eni['network_interfaces'] | length == 0

- name: Fail when no route is present towards required destination VPC
ansible.builtin.fail:
msg: Kindly check the source route table to ensure a more specific route is present towards required destination VPC
when: connectivity_troubleshooter_local_destination_vpc | default('', true) | trim and connectivity_troubleshooter_local_destination_vpc != dst_vpc_id
when: connectivity_troubleshooter_local_destination_vpc | default('', true) | trim and connectivity_troubleshooter_local_destination_vpc != connectivity_troubleshooter_local__dst_vpc_id

- name: Gather information about Source security groups
amazon.aws.ec2_security_group_info:
filters:
group_id: "{{ item }}"
register: __src_security_groups_info
register: connectivity_troubleshooter_local__src_security_groups_info
with_items: "{{ src_security_groups }}"

- name: Gather information about Destination security group
amazon.aws.ec2_security_group_info:
filters:
group_id: "{{ item }}"
register: __dst_security_groups_info
register: connectivity_troubleshooter_local__dst_security_groups_info
with_items: "{{ dst_security_groups }}"

- name: Set 'src_security_groups_info' and 'dst_security_groups_info' variables
ansible.builtin.set_fact:
src_security_groups_info: "{{ __src_security_groups_info.results | sum(attribute='security_groups', start=[]) }}"
dst_security_groups_info: "{{ __dst_security_groups_info.results | sum(attribute='security_groups', start=[]) }}"
src_security_groups_info: "{{ connectivity_troubleshooter_local__src_security_groups_info.results | sum(attribute='security_groups', start=[]) }}"
dst_security_groups_info: "{{ connectivity_troubleshooter_local__dst_security_groups_info.results | sum(attribute='security_groups', start=[]) }}"

- name: Set 'security_groups_info' variable
ansible.builtin.set_fact:
security_groups_info: "{{ security_groups_info | default([]) + item.security_groups }}"
with_items:
- "{{ __src_security_groups_info.results }}"
- "{{ __dst_security_groups_info.results }}"
- "{{ connectivity_troubleshooter_local__src_security_groups_info.results }}"
- "{{ connectivity_troubleshooter_local__dst_security_groups_info.results }}"

- name: Evaluate ingress and egress security group rules
cloud.aws_troubleshooting.eval_security_groups:
Expand All @@ -66,19 +66,19 @@
dst_port: "{{ connectivity_troubleshooter_local_destination_port }}"
dst_security_groups: "{{ dst_security_groups }}"
security_groups: "{{ security_groups_info }}"
register: __result_eval_security_groups
register: connectivity_troubleshooter_local__result_eval_security_groups

- name: Gather information about Source subnet network ACLs
community.aws.ec2_vpc_nacl_info:
filters:
association.subnet-id:
- "{{ src_subnet_id }}"
register: __network_acls_info
register: connectivity_troubleshooter_local__network_acls_info

- name: Set 'src_network_acls_info' variable
- name: Set 'connectivity_troubleshooter_local__src_network_acls_info' variable
ansible.builtin.set_fact:
src_network_acls_info: "{{ src_network_acls_info | d([]) + [dict(_keys | zip(_vals))] }}"
loop: "{{ __network_acls_info.nacls }}"
connectivity_troubleshooter_local__src_network_acls_info: "{{ connectivity_troubleshooter_local__src_network_acls_info | d([]) + [dict(_keys | zip(_vals))] }}"
loop: "{{ connectivity_troubleshooter_local__network_acls_info.nacls }}"
vars:
_keys: "{{ ['egress', 'ingress'] }}"
_vals: "{{ ['egress', 'ingress'] | map('extract', item) }}"
Expand All @@ -88,24 +88,24 @@
filters:
association.subnet-id:
- "{{ dst_subnet_id }}"
register: __network_acls_info
register: connectivity_troubleshooter_local__network_acls_info

- name: Set 'dst_network_acls_info' variable
ansible.builtin.set_fact:
dst_network_acls_info: "{{ dst_network_acls_info | d([]) + [dict(_keys | zip(_vals))] }}"
loop: "{{ __network_acls_info.nacls }}"
connectivity_troubleshooter_local__dst_network_acls_info: "{{ connectivity_troubleshooter_local__dst_network_acls_info | d([]) + [dict(_keys | zip(_vals))] }}"
loop: "{{ connectivity_troubleshooter_local__network_acls_info.nacls }}"
vars:
_keys: "{{ ['egress', 'ingress'] }}"
_vals: "{{ ['egress', 'ingress'] | map('extract', item) }}"

- name: Evaluate ingress and egress netwok ACLs
cloud.aws_troubleshooting.eval_network_acls:
src_ip: "{{ connectivity_troubleshooter_local_source_ip }}"
src_subnet_id: "{{ src_subnet_id }}"
src_subnet_id: "{{ connectivity_troubleshooter_local__src_subnet_id }}"
src_port_range: "{{ connectivity_troubleshooter_local_source_port_range }}"
dst_ip: "{{ connectivity_troubleshooter_local_destination_ip }}"
dst_port: "{{ connectivity_troubleshooter_local_destination_port }}"
dst_subnet_id: "{{ dst_subnet_id }}"
src_network_acls: "{{ src_network_acls_info }}"
dst_network_acls: "{{ dst_network_acls_info }}"
register: __result_eval_network_acls
dst_subnet_id: "{{ connectivity_troubleshooter_local__dst_subnet_id }}"
src_network_acls: "{{ connectivity_troubleshooter_local__src_network_acls_info }}"
dst_network_acls: "{{ connectivity_troubleshooter_local__dst_network_acls_info }}"
register: connectivity_troubleshooter_local__result_eval_network_acls
Loading

0 comments on commit dd571bd

Please sign in to comment.