<commit_before>---
# Provision hosts and other necessary infrastructure.

- name: provision hosts
  hosts: local
  connection: local
  gather_facts: no
  vars_files:
  - vars.yml
  - credentials.yml
  tasks:

  - name: worker hosts
    rax:
      state: present
      name: deconst-worker-%03d
      group: deconst-worker
      count: "{{ worker_count }}"
      exact_count: yes
      image: "{{ image_id_coreos_beta }}"
      flavor: "{{ worker_flavor }}"
      key_name: "{{ rackspace_keyname }}"
      wait: yes
    register: rax_build_workers

  - name: add newly provisioned workers to the correct groups
    add_host:
      name: "{{ item.name }}"
      ansible_ssh_host: "{{ item.rax_accessipv4 }}"
      fresh_host: yes
      groups: deconst-worker
    when: rax_build_workers.action == "create"
    with_items: rax_build_workers.success

  - name: identify full cluster rebuilds
    set_fact:
      fresh_cluster: "{{ (rax_build_workers.action == 'create' and rax_build_workers.success | length == worker_count) | bool }}"

  - name: presenter load balancer
    rax_clb:
      name: deconst-presenter
      port: "{{ presenter_lb_port }}"
      wait: yes
      state: present
    register: clb_presenter

  - name: locate the load balancer VIP
    set_fact: clb_vip_id={{ clb_presenter.balancer.virtual_ips[0].id }}

  - name: content service load balancer
    rax_clb:
      name: deconst-content-service
      port: "{{ content_service_lb_port }}"
      vip_id: "{{ clb_vip_id }}"
      wait: yes
      state: present
    register: clb_content_service

  - name: webhook service load balancer
    rax_clb:
      name: deconst-webhook-service
      port: "{{ webhook_service_lb_port }}"
      vip_id: "{{ clb_vip_id }}"
      wait: yes
      state: present
    register: clb_webhook_service

  - name: force the generation of a new token for a fresh cluster
    file: path=.etcd_cluster_token state=absent
    when: fresh_cluster

  - name: etcd cluster token
    set_fact:
      etcd_cluster_token: "{{ lookup('password', '.etcd_cluster_token length=20') }}"

- name: pause to ensure SSH is up
  hosts: deconst-all
  gather_facts: no
  tasks:

  - name: ensure SSH is listening on all hosts
    local_action: wait_for host={{ hostvars[inventory_hostname].ansible_ssh_host }} port=22 state=started<commit_msg>Trust newly launched hosts.<commit_after>---
# Provision hosts and other necessary infrastructure.

- name: provision hosts
  hosts: local
  connection: local
  gather_facts: no
  vars_files:
  - vars.yml
  - credentials.yml
  tasks:

  - name: worker hosts
    rax:
      state: present
      name: deconst-worker-%03d
      group: deconst-worker
      count: "{{ worker_count }}"
      exact_count: yes
      image: "{{ image_id_coreos_beta }}"
      flavor: "{{ worker_flavor }}"
      key_name: "{{ rackspace_keyname }}"
      wait: yes
    register: rax_build_workers

  - name: add newly provisioned workers to the correct groups
    add_host:
      name: "{{ item.name }}"
      ansible_ssh_host: "{{ item.rax_accessipv4 }}"
      fresh_host: yes
      groups: deconst-worker
    when: rax_build_workers.action == "create"
    with_items: rax_build_workers.success

  - name: identify full cluster rebuilds
    set_fact:
      fresh_cluster: "{{ (rax_build_workers.action == 'create' and rax_build_workers.success | length == worker_count) | bool }}"

  - name: presenter load balancer
    rax_clb:
      name: deconst-presenter
      port: "{{ presenter_lb_port }}"
      wait: yes
      state: present
    register: clb_presenter

  - name: locate the load balancer VIP
    set_fact: clb_vip_id={{ clb_presenter.balancer.virtual_ips[0].id }}

  - name: content service load balancer
    rax_clb:
      name: deconst-content-service
      port: "{{ content_service_lb_port }}"
      vip_id: "{{ clb_vip_id }}"
      wait: yes
      state: present
    register: clb_content_service

  - name: webhook service load balancer
    rax_clb:
      name: deconst-webhook-service
      port: "{{ webhook_service_lb_port }}"
      vip_id: "{{ clb_vip_id }}"
      wait: yes
      state: present
    register: clb_webhook_service

  - name: force the generation of a new token for a fresh cluster
    file: path=.etcd_cluster_token state=absent
    when: fresh_cluster

  - name: etcd cluster token
    set_fact:
      etcd_cluster_token: "{{ lookup('password', '.etcd_cluster_token length=20') }}"

- name: pause to ensure SSH is up
  hosts: deconst-all
  gather_facts: no
  tasks:

  - name: ensure SSH is listening on all hosts
    local_action: wait_for host={{ hostvars[inventory_hostname].ansible_ssh_host }} port=22 state=started

- name: collect SSH public keys of newly launched hosts
  hosts: local
  connection: local
  gather_facts: no
  vars_files:
  - vars.yml
  - credentials.yml
  tasks:

  - name: trust newly launched hosts
    lineinfile:
      dest: "{{ lookup('env', 'HOME') }}/.ssh/known_hosts"
      create: yes
      state: present
      line: "{{ lookup('pipe', 'ssh-keyscan -t rsa ' + item.rax_accessipv4 )}}"
      regexp: "^{{ item.rax_accessipv4 }}"
    with_items: rax_build_workers.success
{'fraction_non_alphanumeric': 0.1022196261682243, 'fraction_numerical': 0.0035046728971962616, 'mean_word_length': 3.0101483216237312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '565227', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1680, 'n_words': 431}