1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- ---
- - hosts: localhost
- connection: local
- gather_facts: false
- tasks:
- - include_vars: "{{ item }}"
- with_first_found:
- - vars.yml
- - vars.yaml
- - name: list available AMIs
- ec2_ami_facts:
- region: "{{ aws_region }}"
- filters: "{{ aws_ami_tags }}"
- register: ami_facts
- when: aws_image is not defined
- - name: determine which AMI to use
- set_fact:
- aws_image: "{{ ami_facts.images[-1].image_id }}"
- when: aws_image is not defined
- - name: determine which AMI to use
- set_fact:
- aws_image: "{{ ami_facts.images[-1].image_id }}"
- when: aws_image is not defined
- - name: Create EC2 instance
- ec2:
- region: "{{ aws_region }}"
- key_name: "{{ aws_key }}"
- instance_type: "{{ item.aws_flavor }}"
- image: "{{ item.aws_image | default(aws_image) }}"
- wait: yes
- group: "{{ item.aws_security_group }}"
- count: 1
- vpc_subnet_id: "{{ aws_subnet }}"
- assign_public_ip: yes
- instance_tags: "{{ aws_instance_tags }}"
- volumes: "{{ item.aws_volumes | default(omit) }}"
- register: ec2
- with_items: "{{ aws_instances }}"
- vars:
- aws_instance_tags: |
- {
- "kubernetes.io/cluster/{{ aws_cluster_id }}": "true",
- "Name": "{{ item.name }}",
- "ansible-groups": "{{ item.ansible_groups | join(',') }}",
- "ansible-node-group": "{{ item.node_group }}",
- "expirationDate": "{{ item.aws_expiration_date | default(aws_expiration_date) }}"
- }
- - name: Add machine to inventory
- add_host:
- name: "{{ item.instances.0.tags['Name'] }}"
- ansible_host: "{{ item.instances.0.dns_name }}"
- ansible_user: "{{ item.instances.0.aws_user | default(aws_user)}}"
- groups: "{{ item.instances.0.tags['ansible-groups'].split(',') }}"
- aws_region: "{{ aws_region }}"
- aws_ip: "{{ item.instances.0.public_ip }}"
- aws_id: "{{ item.instances.0.id }}"
- openshift_node_group_name: "{{ item.instances.0.tags['ansible-node-group'] }}"
- with_items: "{{ ec2.results }}"
- - name: write the inventory
- template:
- src: ./template-inventory.j2
- dest: "inventory/hosts"
- - name: Refresh inventory to ensure new instances exist in inventory
- meta: refresh_inventory
- - hosts: all
- gather_facts: no
- become: true
- tasks:
- - wait_for_connection: {}
- - setup: {}
- - import_playbook: ../../playbooks/openshift-node/network_manager.yml
- - import_playbook: ../../playbooks/prerequisites.yml
- - import_playbook: ../../playbooks/deploy_cluster.yml
|