aboutsummaryrefslogtreecommitdiffstats
path: root/ansible/roles/infra_prepare_vms/tasks/main.yml
blob: 4e0d9c373d543c9b68054c93e90535ed09a205d8 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright (c) 2018 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: Include input file
  include_vars:
    file: "{{ rs_file }}"
    name: infra_deploy_vars

- name: Install setuptools
  apt:
    name: python-setuptools

- name: Install pip
  shell: easy_install pip
  environment: "{{ proxy_env }}"

- name: Install dependency for dns dig
  pip:
    name: dnspython
    state: latest

- set_fact:
    block_str: "{{ block_str | default('') + item.interfaces[0].ip + ' ' + item.hostname + '\n'}}"
  with_items: "{{ infra_deploy_vars.nodes }}"

- name: Delete hosts between markers
  blockinfile:
    path: /etc/hosts
    marker: "# {mark} generated hosts file"
    content: ""

- name: Update /etc/hosts
  blockinfile:
    path: /etc/hosts
    block: |
      {{ block_str }}
    marker: "# {mark} generated hosts file"

- name: Clear known hosts
  shell: >
    ssh-keygen -f /root/.ssh/known_hosts -R "{{ item.interfaces[0].ip }}";
    ssh-keygen -f /root/.ssh/known_hosts -R "{{ item.hostname }}"
  with_items: "{{ infra_deploy_vars.nodes }}"

- set_fact:
    controllers: "{{ controllers | default([]) + [item.hostname] }}"
  when:
    - item.openstack_node is defined
    - item.openstack_node == 'controller'
  with_items: "{{ infra_deploy_vars.nodes }}"

- name: Add host controller as deploy
  add_host:
    hostname: "{{ item.hostname }}"
    host_ip: "{{ item.interfaces[0].ip }}"
    groups: deploy, ostack
    ansible_host: "{{ item.hostname }}"
    ansible_user: "{{ item.user }}"
    ansible_ssh_pass: "{{ item.password }}"
    node_type: "{{ item.openstack_node }}"
    secondary_ip: "{{ item.interfaces[1].ip }}"
  when: item.hostname == controllers[0]
  with_items: "{{ infra_deploy_vars.nodes }}"

- name: Add hosts others as controller, compute
  add_host:
    hostname: "{{ item.hostname }}"
    host_ip: "{{ item.interfaces[0].ip }}"
    groups: regular,ostack
    ansible_host: "{{ item.hostname }}"
    ansible_user: "{{ item.user }}"
    ansible_ssh_pass: "{{ item.password }}"
    node_type: "{{ item.openstack_node }}"
    secondary_ip: "{{ item.interfaces[1].ip }}"
  when:
    - item.openstack_node is defined
    - item.openstack_node == 'controller' or item.openstack_node == 'compute'
    - item.hostname != controllers[0]
  with_items: "{{ infra_deploy_vars.nodes }}"

- name: Add yardstick host to group
  add_host:
    hostname: "{{ item.hostname }}"
    host_ip: "{{ item.interfaces[0].ip }}"
    groups: yardstickG
    ansible_host: "{{ item.hostname }}"
    ansible_user: "{{ item.user }}"
    ansible_ssh_pass: "{{ item.password }}"
    secondary_ip: "{{ item.interfaces[1].ip }}"
  when: item.hostname == 'yardstickvm'
  with_items: "{{ infra_deploy_vars.nodes }}"