2

Ansible Playbook を使用して VPC B を作成しました。ここで、VPC B と VPC A の間で VPC ピアリングを行いたいと考えています。VPC ピアリングを作成し、VPC ピアリング接続をアクティブ化できます。

しかし、新しい vpc_peering_id を使用して VPC A の既存のルート テーブル エントリを追加/編集する方法に苦労しています。

4

3 に答える 3

2

Ansible でいつでもシェルアウトできますが、冪等性とフローと出力のより優れた制御をもたらす必要があるため、可能であればモジュールを使用することをお勧めします。

したがって、この場合ec2_vpc_route_table、Ansible 2 でリリースされたモジュールを使用する必要があります。

基本的な例は次のようになります。

- name: private route table
  ec2_vpc_route_table:
    vpc_id: "{{ vpc_a_id }}"
    region: "{{ ec2_region }}"
    tags:
      Name: private
    subnets:
      - "{{ private_subnet_a.id }}"
      - "{{ private_subnet_b.id }}"
      - "{{ private_subnet_c.id }}"
    routes:
      - dest: 0.0.0.0/0
        gateway_id: "{{ nat_instance }}"
      - dest: "{{ vpc_b_cidr }}"
        gateway_id: "{{ vpc_a_to_b_pcx_id }}"
  register: private_route_table

これにより、3 つのプライベート サブネットに関連付けられ、2 つのルートを持つルート テーブルが作成されます。1 つはその VPC の CIDR 範囲の VPC B への VPC ピアリング ルートであり、もう 1 つは NAT 経由でインターネットに接続されるデフォルト ルートです。インスタンス/ゲートウェイ。

于 2016-07-14T07:54:58.720 に答える
2

ありがとう@PrashantB

現在のルートを置き換えるのではなく、新しいルートを追加したいので、create-route に変更しました。また、ピアリング接続のセットアップの前後にリージョンを変更する必要があります

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

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

ループ結果を含む Ansible Playbook 内のコード

    - 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
于 2019-05-01T17:32:19.377 に答える