- hosts: localhost
  connection: local
  gather_facts: no
  vars_files:
    - vars/ec2_security_groups.yaml

  vars:
    provision: false

  tasks:
    - name: provision dkron host
      ec2:
        exact_count: 1
        count_tag:
          Role: dkron

        image: ami-61074c01 # Ubuntu 14.04.5 LTS hvm-ssd
        instance_type: t2.small
        region: us-west-1
        instance_tags:
          Role: dkron
          Name: DKRON

        key_name: aws_mturk
        vpc_subnet_id: subnet-ca192a93 # LoggingMonitoring us-west-1
        group:
          - LoggingMonitoring
        assign_public_ip: no
        private_ip: 10.1.14.43
      register: server
      when: provision

    - name: wait for provisioned servers to start ssh
      wait_for:
        host: "{{ item.private_ip }}"
        port: 22
      with_items: "{{ server.instances }}"
      when: provision

    - name: accept new ssh fingerprints
      shell: ssh-keyscan -H {{ item.private_ip }} >> ~/.ssh/known_hosts
      with_items: "{{ server.instances }}"
      when: provision

- hosts: tag_Role_dkron
  roles:
    - role: ansible-role-dns
      become: yes
      dns_domain: 'us-west-1.compute.internal'
      dns_searchs:
        - 'zooxlabs.com'
        - 'us-west-1.compute.internal'
      dns_nameservers: ["172.16.10.26", "172.16.10.25", "10.1.0.2"]
    - role: nfsclient
    - role: docker-host
    - role: dkron
