diff --git a/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2.yaml b/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2.yaml index ed2eaa9e..fa386a6a 100644 --- a/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2.yaml +++ b/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2.yaml @@ -86,16 +86,27 @@ delete_on_termination: true vpc_subnet_id: "{{ item.subnet }}" wait: yes - with_items: - - name: "master1" - subnet: "{{ subnet_private.results.0.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_master }}" - - name: "master2" - subnet: "{{ subnet_private.results.1.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_master }}" - - name: "master3" - subnet: "{{ subnet_private.results.2.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_master }}" + with_items: "\ +{%- set i = 1 -%} +{%- set j = 0 -%} +{%- for k in range(0, ( ec2_count_master if ec2_count_master is defined else 3 ) ) -%} + { +'name': 'master{{ i }}', +'subnet': '{{ subnet_private.results[j].subnet.id if subnet_private is defined else '' }}', +'type': '{{ ec2_type_master }}' + }, + {%- if i <= ( ec2_count_master if ec2_count_master is defined else 3 ) -%} + {%- set i = i + 1 -%} + {%- endif -%} + {%- if subnet_private is defined -%} + {%- if j < subnet_private.results | length - 1 -%} + {%- set j = j + 1 -%} + {%- else -%} + {%- set j = 0 -%} + {%- endif -%} + {%- endif -%} +{%- endfor -%} + " retries: 3 delay: 3 register: ec2master @@ -176,16 +187,27 @@ volume_size: 100 vpc_subnet_id: "{{ item.subnet }}" wait: yes - with_items: - - name: "infra1" - subnet: "{{ subnet_private.results.0.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_infra }}" - - name: "infra2" - subnet: "{{ subnet_private.results.1.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_infra }}" - - name: "infra3" - subnet: "{{ subnet_private.results.2.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_infra }}" + with_items: "\ +{%- set i = 1 -%} +{%- set j = 0 -%} +{%- for k in range(0, ( ec2_count_infra if ec2_count_infra is defined else 3 ) ) -%} + { +'name': 'infra{{ i }}', +'subnet': '{{ subnet_private.results[j].subnet.id if (state is undefined or 'absent' not in state) else '' }}', +'type': '{{ ec2_type_infra }}' + }, + {%- if i <= ( ec2_count_infra if ec2_count_infra is defined else 3 ) -%} + {%- set i = i + 1 -%} + {%- endif -%} + {%- if subnet_private is defined -%} + {%- if j < subnet_private.results | length - 1 -%} + {%- set j = j + 1 -%} + {%- else -%} + {%- set j = 0 -%} + {%- endif -%} + {%- endif -%} +{%- endfor -%} + " retries: 3 delay: 3 register: ec2infra @@ -257,16 +279,27 @@ volume_size: 100 vpc_subnet_id: "{{ item.subnet }}" wait: yes - with_items: - - name: "node1" - subnet: "{{ subnet_private.results.0.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_node }}" - - name: "node2" - subnet: "{{ subnet_private.results.1.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_node }}" - - name: "node3" - subnet: "{{ subnet_private.results.2.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_node }}" + with_items: "\ +{%- set i = 1 -%} +{%- set j = 0 -%} +{%- for k in range(0, ( ec2_count_node if ec2_count_node is defined else 3 ) ) -%} + { +'name': 'node{{ i }}', +'subnet': '{{ subnet_private.results[j].subnet.id if subnet_private is defined else '' }}', +'type': '{{ ec2_type_node }}' + }, + {%- if i <= ( ec2_count_node if ec2_count_node is defined else 3 ) -%} + {%- set i = i + 1 -%} + {%- endif -%} + {%- if subnet_private is defined -%} + {%- if j < subnet_private.results | length - 1 -%} + {%- set j = j + 1 -%} + {%- else -%} + {%- set j = 0 -%} + {%- endif -%} + {%- endif -%} +{%- endfor -%} + " retries: 3 delay: 3 register: ec2node diff --git a/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2_cns.yaml b/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2_cns.yaml index 1fc4cda0..64451b63 100644 --- a/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2_cns.yaml +++ b/reference-architecture/3.9/playbooks/roles/aws/tasks/ec2_cns.yaml @@ -34,16 +34,28 @@ delete_on_termination: true vpc_subnet_id: "{{ item.subnet }}" wait: yes - with_items: - - name: "cns1" - subnet: "{{ subnet_private.results.0.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_cns }}" - - name: "cns2" - subnet: "{{ subnet_private.results.1.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_cns }}" - - name: "cns3" - subnet: "{{ subnet_private.results.2.subnet.id if (state is undefined or 'absent' not in state) else '' }}" - type: "{{ ec2_type_cns }}" + with_items: "\ +{%- set i = 1 -%} +{%- set j = 0 -%} +{%- for k in range(0, ( ec2_count_cns if ec2_count_cns is defined else 3 ) ) -%} + {%- set id = subnet_private.results[j].subnet.id if subnet_private is defined else '' -%} + { +'name': 'cns{{ i }}', +'subnet': '{{ id }}', +'type': '{{ ec2_type_cns }}' + }, + {%- if i <= ( ec2_count_cns if ec2_count_cns is defined else 3 ) -%} + {%- set i = i + 1 -%} + {%- endif -%} + {%- if subnet_private is defined -%} + {%- if j < subnet_private.results | length - 1 -%} + {%- set j = j + 1 -%} + {%- else -%} + {%- set j = 0 -%} + {%- endif -%} + {%- endif -%} +{%- endfor -%} + " retries: 3 delay: 3 register: ec2cns diff --git a/reference-architecture/3.9/playbooks/vars/main.yaml b/reference-architecture/3.9/playbooks/vars/main.yaml index fa21f765..037b7d4d 100644 --- a/reference-architecture/3.9/playbooks/vars/main.yaml +++ b/reference-architecture/3.9/playbooks/vars/main.yaml @@ -21,10 +21,19 @@ subnets_private_cidr: - 172.16.48.0/20 ec2_type_bastion: "t2.medium" + +#ec2_count_master: 3 ec2_type_master: "m5.2xlarge" + +#ec2_count_infra: 3 ec2_type_infra: "m5.2xlarge" + +#ec2_count_node: 3 ec2_type_node: "m5.2xlarge" + +#ec2_count_cns: 3 ec2_type_cns: "m5.2xlarge" rhel_release: "rhel-7.5" + #ec2ami: ami-abc3231a