Thanks @PrashantB
I want to add new route instead of replace current route, so just changed to create-route, also need change region before/after for the peering connection setup
aws configure set default.region us-east-1
aws ec2 create-route --route-table-id rtb-09ddaxxxxxxxxxxxx -destination-cidr-block 10.5.5.0/24 --vpc-peering-connection-id pcx-063xxxxxxxxxx8a1a
aws configure set default.region us-east-2
Code inside Ansible playbook
- name: change region for adding peer connection route to peer route table for peer connection bi-directional
local_action: command aws configure set default.region us-east-1
- name: add peer connection route to peer route table for peer connection bi-directional
local_action: command aws ec2 create-route --route-table-id {{ peer_route_table_id_edge_private }} --destination-cidr-block 10.255.251.0/24 --vpc-peering-connection-id {{ peer_id }}
ignore_errors: yes
register: peer_route
- debug: var=peer_route
- name: change region for adding peer connection route to peer route table for peer connection bi-directional
local_action: command aws configure set default.region us-east-2
Code inside Ansible playbook with loop results
- name: add peer connection route to peer route table for peer connection bi-directional
local_action: command aws ec2 create-route --route-table-id {{ item.route_table.id }} --destination-cidr-block {{ vpc_cidr_block }} --vpc-peering-connection-id {{ peer_id_edge }}
ignore_errors: yes
loop: "{{ private_rtbs_edge.results }}"
register: peer_route
- debug: var=peer_route