--- - 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: {} - name: Make sure hostname is set to public ansible host hostname: name: "{{ ansible_host }}" - name: Detecting Operating System shell: ls /run/ostree-booted ignore_errors: yes failed_when: false register: ostree_output - name: Update all packages package: name: '*' state: latest when: ostree_output.rc != 0 register: yum_update - name: Update Atomic system command: atomic host upgrade when: ostree_output.rc == 0 register: ostree_update - name: Reboot machines shell: sleep 5 && systemctl reboot async: 1 poll: 0 ignore_errors: true when: yum_update | changed or ostree_update | changed - name: Wait for connection wait_for_connection: connect_timeout: 20 sleep: 5 delay: 5 timeout: 300 - setup: {} - import_playbook: ../../playbooks/openshift-node/network_manager.yml - import_playbook: ../../playbooks/prerequisites.yml - import_playbook: ../../playbooks/deploy_cluster.yml