--- - 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 }}", } - 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/prerequisites.yml - import_playbook: ../../playbooks/deploy_cluster.yml