aboutsummaryrefslogtreecommitdiffstats
path: root/deployment/noheat/infra-openstack/ansible/roles/create_hosts/tasks/create_host.yml
blob: c217abaa9de14ca9a6f6dca1c3ce58c9e2ed0a28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
- name: Create host
  os_server:
    state: present
    name: "{{ host.name }}"
    image: "{{ host.image }}"
    flavor: "{{ host.flavor }}"
    key_name: "{{ host.keypair }}"
    network: "{{ host.network }}"
    security_groups:
      - "{{ host.securitygroup }}"
    auto_ip: "{{ host.auto_ip | default(true) }}"
    boot_from_volume: true
    terminate_volume: true
    volume_size: "{{ host.volume_size | default(10) }}"
    userdata: |
      #cloud-config
      ssh_authorized_keys:
        - "{{ operator_key }}"
  register: new_host

- name: Add host to inventory
  add_host:
    hostname: "{{ new_host.server.name }}"
    groups: "{{ cluster.name }}"
    ansible_ssh_host: "{{ new_host.server.public_v4 }}"
    ansible_ssh_user: "{{ image.user }}"
    ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"
    ansible_ssh_private_key_file: "~/.ssh/{{ keypair.key.name }}"

- name: Add host to hosts dict
  set_fact:
    hosts_dict: "{{ hosts_dict|default({}) | combine( {new_host.server.name: new_host.server.private_v4} ) }}"