Skip to content

Commit

Permalink
Yet another round of 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 Aug 14, 2023
1 parent ba47f5e commit f26c169
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 91 deletions.
1 change: 1 addition & 0 deletions roles/aws_setup_credentials/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- name: Define intial value for credentials
ansible.builtin.set_fact:
aws_setup_credentials__output: {}

- name: Create auth credentials
ansible.builtin.include_tasks: read_option.yml
with_dict: "{{ aws_connection_env }}"
15 changes: 8 additions & 7 deletions roles/connectivity_troubleshooter/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
# tasks file for roles/connectivity_troubleshooter
- name: Run 'connectivity_troubleshooter'
- name: Run cloud.aws_troubleshooting.connectivity_troubleshooter
module_defaults:
group/aws: "{{ aws_setup_credentials__output }}"

block:
- name: Include 'connectivity_troubleshooter_validate' role
- name: Include cloud.aws_troubleshooting.connectivity_troubleshooter_validate role
ansible.builtin.include_role:
name: cloud.aws_troubleshooting.connectivity_troubleshooter_validate
vars:
Expand All @@ -17,9 +17,10 @@
- name: Fail when next hop type is not supported by this role
ansible.builtin.fail:
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-')
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
- name: Include cloud.aws_troubleshooting.connectivity_troubleshooter_local role
ansible.builtin.include_role:
name: cloud.aws_troubleshooting.connectivity_troubleshooter_local
vars:
Expand All @@ -30,7 +31,7 @@
connectivity_troubleshooter_local_source_port_range: "{{ connectivity_troubleshooter_source_port_range }}"
when: "'local' == connectivity_troubleshooter_validate__next_hop"

- name: Include 'connectivity_troubleshooter_igw' role
- name: Include cloud.aws_troubleshooting.connectivity_troubleshooter_igw role
ansible.builtin.include_role:
name: cloud.aws_troubleshooting.connectivity_troubleshooter_igw
vars:
Expand All @@ -42,7 +43,7 @@
connectivity_troubleshooter_igw_source_port_range: "{{ connectivity_troubleshooter_source_port_range }}"
when: "'igw-' in connectivity_troubleshooter_validate__next_hop"

- name: Include 'connectivity_troubleshooter_nat' role
- name: Include cloud.aws_troubleshooting.connectivity_troubleshooter_nat role
ansible.builtin.include_role:
name: cloud.aws_troubleshooting.connectivity_troubleshooter_nat
vars:
Expand All @@ -52,7 +53,7 @@
connectivity_troubleshooter_nat_source_port_range: "{{ connectivity_troubleshooter_source_port_range }}"
when: "'nat-' in connectivity_troubleshooter_validate__next_hop"

- name: Include 'connectivity_troubleshooter_peering' role
- name: Include cloud.aws_troubleshooting.connectivity_troubleshooter_peering role
ansible.builtin.include_role:
name: cloud.aws_troubleshooting.connectivity_troubleshooter_peering
vars:
Expand Down
18 changes: 10 additions & 8 deletions roles/connectivity_troubleshooter_igw/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
---
# tasks file for roles/connectivity_troubleshooter_igw
- name: Run 'connectivity_troubleshooter_igw' role
- name: Run cloud.aws_troubleshooting.connectivity_troubleshooter_igw role
block:
- name: Fail when next hop type is not supported by this role
ansible.legacy.fail:
msg: Next hop type '{{ connectivity_troubleshooter_validate__next_hop }}' is not supported by this role
when: "'igw-' not in connectivity_troubleshooter_validate__next_hop"

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

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

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

- name: Set 'connectivity_troubleshooter_igw__src_security_groups_info' variable
- name: Set source security groups info
ansible.legacy.set_fact:
connectivity_troubleshooter_igw__src_security_groups_info: "{{ connectivity_troubleshooter_igw__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 @@ -42,5 +44,5 @@
dst_port: "{{ connectivity_troubleshooter_igw_destination_port }}"
src_network_interface: "{{ src_network_interface }}"
src_security_groups_info: "{{ connectivity_troubleshooter_igw__src_security_groups_info }}"
src_network_acls: "{{connectivity_troubleshooter_igw__src_subnet_nacls }}"
src_network_acls: "{{ connectivity_troubleshooter_igw__src_subnet_nacls }}"
register: connectivity_troubleshooter_igw__result_eval_src_igw_route
40 changes: 23 additions & 17 deletions roles/connectivity_troubleshooter_local/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
# tasks file for roles/connectivity_troubleshooter_local

- name: Run 'connectivity_troubleshooter_local' role
- name: Run cloud.aws_troubleshooting.connectivity_troubleshooter_local role
block:
- name: Fail when next hop type is not supported by this role
ansible.builtin.fail:
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
- name: Gather information about destination ENI
amazon.aws.ec2_eni_info:
filters:
addresses.private-ip-address: "{{ connectivity_troubleshooter_local_destination_ip }}"
register: connectivity_troubleshooter_local__describe_dst_eni

- name: Set 'connectivity_troubleshooter_local__dst_vpc_id', 'connectivity_troubleshooter_local__dst_subnet_id' and 'connectivity_troubleshooter_local__dst_security_groups' variables
- name: Set destination VPC id, subnet id and security groups
ansible.builtin.set_fact:
connectivity_troubleshooter_local__dst_vpc_id: "{{ connectivity_troubleshooter_local__dst_network_interface_info.vpc_id }}"
connectivity_troubleshooter_local__dst_subnet_id: "{{ connectivity_troubleshooter_local__dst_network_interface_info.subnet_id }}"
connectivity_troubleshooter_local__dst_security_groups: "{{ connectivity_troubleshooter_local__dst_network_interface_info.groups | map(attribute='group_id') | list }}"
connectivity_troubleshooter_local__dst_security_groups: "{{ connectivity_troubleshooter_local__dst_network_interface_info.groups | map(attribute='group_id')
| list }}"
vars:
connectivity_troubleshooter_local__dst_network_interface_info: "{{ connectivity_troubleshooter_local__describe_dst_eni.network_interfaces.0 }}"

Expand All @@ -32,28 +33,31 @@
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 != connectivity_troubleshooter_local__dst_vpc_id

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

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

- name: Set 'connectivity_troubleshooter_local__src_security_groups_info' and 'connectivity_troubleshooter_local__dst_security_groups_info' variables
- name: Set source and destination security groups info
ansible.builtin.set_fact:
connectivity_troubleshooter_local__src_security_groups_info: "{{ connectivity_troubleshooter_local__src_security_groups_info.results | sum(attribute='security_groups', start=[]) }}"
connectivity_troubleshooter_local__dst_security_groups_info: "{{ connectivity_troubleshooter_local__dst_security_groups_info.results | sum(attribute='security_groups', start=[]) }}"
connectivity_troubleshooter_local__src_security_groups_info: "{{ connectivity_troubleshooter_local__src_security_groups_info.results | sum(attribute='security_groups',
start=[]) }}"
connectivity_troubleshooter_local__dst_security_groups_info: "{{ connectivity_troubleshooter_local__dst_security_groups_info.results | sum(attribute='security_groups',
start=[]) }}"

- name: Set 'connectivity_troubleshooter_local__security_groups_info' variable
- name: Set security groups info
ansible.builtin.set_fact:
connectivity_troubleshooter_local__security_groups_info: "{{ connectivity_troubleshooter_local__security_groups_info | default([]) + item.security_groups }}"
connectivity_troubleshooter_local__security_groups_info: "{{ connectivity_troubleshooter_local__security_groups_info | default([]) + item.security_groups
}}"
with_items:
- "{{ connectivity_troubleshooter_local__src_security_groups_info.results }}"
- "{{ connectivity_troubleshooter_local__dst_security_groups_info.results }}"
Expand All @@ -68,31 +72,33 @@
security_groups: "{{ connectivity_troubleshooter_local__security_groups_info }}"
register: connectivity_troubleshooter_local__result_eval_security_groups

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

- name: Set 'connectivity_troubleshooter_local__src_network_acls_info' variable
- name: Set source NACLs info
ansible.builtin.set_fact:
connectivity_troubleshooter_local__src_network_acls_info: "{{ connectivity_troubleshooter_local__src_network_acls_info | d([]) + [dict(_keys | zip(_vals))] }}"
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) }}"

- name: Gather information about Destination network ACLs
- name: Gather information about destination network ACLs
community.aws.ec2_vpc_nacl_info:
filters:
association.subnet-id:
- "{{ dst_subnet_id }}"
register: connectivity_troubleshooter_local__network_acls_info

- name: Set 'connectivity_troubleshooter_local__dst_network_acls_info' variable
- name: Set destination NACLs info
ansible.builtin.set_fact:
connectivity_troubleshooter_local__dst_network_acls_info: "{{ connectivity_troubleshooter_local__dst_network_acls_info | d([]) + [dict(connectivity_troubleshooter_local__keys | zip(connectivity_troubleshooter_local__vals))] }}"
connectivity_troubleshooter_local__dst_network_acls_info: "{{ connectivity_troubleshooter_local__dst_network_acls_info | d([]) + [dict(connectivity_troubleshooter_local__keys
| zip(connectivity_troubleshooter_local__vals))] }}"
loop: "{{ connectivity_troubleshooter_local__network_acls_info.nacls }}"
vars:
connectivity_troubleshooter_local__keys: "{{ ['egress', 'ingress'] }}"
Expand Down
13 changes: 7 additions & 6 deletions roles/connectivity_troubleshooter_nat/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# tasks file for roles/connectivity_troubleshooter_nat

- name: Run 'connectivity_troubleshooter_nat' role
- name: Run cloud.aws_troubleshooting.connectivity_troubleshooter_nat role
block:
- name: Fail when next hop type is not supported by this role
ansible.builtin.fail:
Expand All @@ -14,7 +14,7 @@
nat-gateway-id: "{{ connectivity_troubleshooter_validate__next_hop }}"
register: connectivity_troubleshooter_nat__describe_nat_gw

- name: Set 'connectivity_troubleshooter_nat__nat_subnet_id' and 'connectivity_troubleshooter_nat__nat_vpc_id' variables
- name: Set NAT subnet id and NAT VPC id
ansible.builtin.set_fact:
connectivity_troubleshooter_nat__nat_subnet_id: "{{ connectivity_troubleshooter_nat__nat_gw_info.subnet_id }}"
connectivity_troubleshooter_nat__nat_vpc_id: "{{ connectivity_troubleshooter_nat__nat_gw_info.vpc_id }}"
Expand All @@ -27,9 +27,10 @@
association.subnet-id: "{{ connectivity_troubleshooter_nat__describe_nat_gwnat_subnet_id }}"
register: connectivity_troubleshooter_nat__nat_network_acls_info

- name: Set 'connectivity_troubleshooter__nat_network_acls' variable
- name: Set NAT NACLs
ansible.builtin.set_fact:
connectivity_troubleshooter_nat__nat_network_acls: "{{ connectivity_troubleshooter_nat__nat_network_acls | d([]) + [dict(connectivity_troubleshooter_nat__keys | zip(connectivity_troubleshooter_nat__vals))] }}"
connectivity_troubleshooter_nat__nat_network_acls: "{{ connectivity_troubleshooter_nat__nat_network_acls | d([]) + [dict(connectivity_troubleshooter_nat__keys
| zip(connectivity_troubleshooter_nat__vals))] }}"
loop: "{{ connectivity_troubleshooter_nat__nat_network_acls_info.nacls }}"
vars:
connectivity_troubleshooter_nat__keys: "{{ ['egress', 'ingress'] }}"
Expand All @@ -42,7 +43,7 @@
- "{{ connectivity_troubleshooter_nat__nat_subnet_id }}"
register: connectivity_troubleshooter_nat__nat_route_table

- name: Set 'nat_routes' variable
- name: Set NAT routes
ansible.builtin.set_fact:
connectivity_troubleshooter_nat__nat_routes: "{{ connectivity_troubleshooter_nat__nat_route_table.route_tables.0.routes }}"
when: connectivity_troubleshooter_nat__nat_route_table.route_tables | length > 0
Expand All @@ -63,7 +64,7 @@
msg: Could not find route table for NAT Gateway
when: connectivity_troubleshooter_nat__nat_route_table_retry.route_tables | length == 0

- name: Set 'nat_routes' variable
- name: Set NAT routest
ansible.builtin.set_fact:
connectivity_troubleshooter_nat__nat_routes: "{{ connectivity_troubleshooter_nat__nat_route_table_retry.route_tables.0.routes }}"

Expand Down
16 changes: 8 additions & 8 deletions roles/connectivity_troubleshooter_peering/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# tasks file for roles/connectivity_troubleshooter_peering_destination

- name: Run 'connectivity_troubleshooter_peering' role
- name: Run cloud.aws_troubleshooting.connectivity_troubleshooter_peering role
block:
- name: Fail when next hop type is not supported by this role
ansible.builtin.fail:
Expand All @@ -15,27 +15,27 @@
- "{{ connectivity_troubleshooter_validate__next_hop }}"
register: connectivity_troubleshooter_peering__vpc_peering_connection_info

- name: Gather information about Network Interface of the Destination peer
- name: Gather information about Network Interface of the destination peer
amazon.aws.ec2_eni_info:
filters:
addresses.private-ip-address: "{{ connectivity_troubleshooter_peering_destination_ip }}"
register: connectivity_troubleshooter_peering__dst_peer_eni

- name: Set 'connectivity_troubleshooter_peering__dst_peer_vpc_id' and 'connectivity_troubleshooter_peering__dst_peer_subnet_id' variables
- name: Set destination peer VPC id and subnet id
ansible.builtin.set_fact:
connectivity_troubleshooter_peering__dst_peer_vpc_id: "{{ connectivity_troubleshooter_peering__dst_peer_eni_info.vpc_id }}"
connectivity_troubleshooter_peering__dst_peer_subnet_id: "{{ connectivity_troubleshooter_peering__dst_peer_eni_info.subnet_id }}"
vars:
connectivity_troubleshooter_peering__dst_peer_eni_info: "{{ connectivity_troubleshooter_peering__dst_peer_eni.network_interfaces.0 }}"

- name: Gather information about Destination peer subnet
- name: Gather information about destination peer subnet
amazon.aws.ec2_vpc_route_table_info:
filters:
association.subnet-id:
- "{{ connectivity_troubleshooter_peering__dst_peer_subnet_id }}"
register: connectivity_troubleshooter_peering__dst_peer_route_table

- name: Set 'routes' variable
- name: Set routes
ansible.builtin.set_fact:
connectivity_troubleshooter_validate__routes: "{{ connectivity_troubleshooter_peering__dst_peer_route_table.route_tables.0.routes }}"
when: connectivity_troubleshooter_peering__dst_peer_route_table.route_tables | length > 0
Expand All @@ -44,19 +44,19 @@
- name: Gather information about VPC route table using association.main=true
when: connectivity_troubleshooter_peering__dst_peer_route_table.route_tables | length == 0
block:
- name: Gather information about Destination peer subnet
- name: Gather information about destination peer subnet
amazon.aws.ec2_vpc_route_table_info:
filters:
association.main: "true"
vpc-id: "{{ connectivity_troubleshooter_peering__dst_peer_vpc_id }}"
register: connectivity_troubleshooter_peering__dst_peer_route_table_retry

- name: Fail when no route table for Destination peer is found
- name: Fail when no route table for destination peer is found
ansible.builtin.fail:
msg: Could not find route table for Destination peer
when: connectivity_troubleshooter_peering__dst_peer_route_table_retry.route_tables | length == 0

- name: Set 'routes' variable
- name: Set routes
ansible.builtin.set_fact:
connectivity_troubleshooter_peering__routes: "{{ connectivity_troubleshooter_peering__dst_peer_route_table_retry.route_tables.0.routes }}"

Expand Down
Loading

0 comments on commit f26c169

Please sign in to comment.