Merge "Check for network already created k8"
[yardstick.git] / ansible / roles / infra_prepare_vms / tasks / main.yml
1 # Copyright (c) 2018 Intel Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 ---
15 - name: Include input file
16   include_vars:
17     file: "{{ rs_file }}"
18     name: infra_deploy_vars
19
20 - name: Install setuptools
21   apt:
22     name: python-setuptools
23
24 - name: Install pip
25   shell: easy_install pip
26   environment: "{{ proxy_env }}"
27
28 - name: Install dependency for dns dig
29   pip:
30     name: dnspython
31     state: latest
32
33 - set_fact:
34     block_str: "{{ block_str | default('') + item.interfaces[0].ip + ' ' + item.hostname + '\n'}}"
35   with_items: "{{ infra_deploy_vars.nodes }}"
36
37 - name: Delete hosts between markers
38   blockinfile:
39     path: /etc/hosts
40     marker: "# {mark} generated hosts file"
41     content: ""
42
43 - name: Update /etc/hosts
44   blockinfile:
45     path: /etc/hosts
46     block: |
47       {{ block_str }}
48     marker: "# {mark} generated hosts file"
49
50 - name: Clear known hosts
51   shell: >
52     ssh-keygen -f /root/.ssh/known_hosts -R "{{ item.interfaces[0].ip }}";
53     ssh-keygen -f /root/.ssh/known_hosts -R "{{ item.hostname }}"
54   with_items: "{{ infra_deploy_vars.nodes }}"
55
56 - set_fact:
57     controllers: "{{ controllers | default([]) + [item.hostname] }}"
58   when:
59     - item.openstack_node is defined
60     - item.openstack_node == 'controller'
61   with_items: "{{ infra_deploy_vars.nodes }}"
62
63 - name: Add host controller as deploy
64   add_host:
65     hostname: "{{ item.hostname }}"
66     host_ip: "{{ item.interfaces[0].ip }}"
67     groups: deploy, ostack
68     ansible_host: "{{ item.hostname }}"
69     ansible_user: "{{ item.user }}"
70     ansible_ssh_pass: "{{ item.password }}"
71     node_type: "{{ item.openstack_node }}"
72     secondary_ip: "{{ item.interfaces[1].ip }}"
73   when: item.hostname == controllers[0]
74   with_items: "{{ infra_deploy_vars.nodes }}"
75
76 - name: Add hosts others as controller, compute
77   add_host:
78     hostname: "{{ item.hostname }}"
79     host_ip: "{{ item.interfaces[0].ip }}"
80     groups: regular,ostack
81     ansible_host: "{{ item.hostname }}"
82     ansible_user: "{{ item.user }}"
83     ansible_ssh_pass: "{{ item.password }}"
84     node_type: "{{ item.openstack_node }}"
85     secondary_ip: "{{ item.interfaces[1].ip }}"
86   when:
87     - item.openstack_node is defined
88     - item.openstack_node == 'controller' or item.openstack_node == 'compute'
89     - item.hostname != controllers[0]
90   with_items: "{{ infra_deploy_vars.nodes }}"
91
92 - name: Add yardstick host to group
93   add_host:
94     hostname: "{{ item.hostname }}"
95     host_ip: "{{ item.interfaces[0].ip }}"
96     groups: yardstickG
97     ansible_host: "{{ item.hostname }}"
98     ansible_user: "{{ item.user }}"
99     ansible_ssh_pass: "{{ item.password }}"
100     secondary_ip: "{{ item.interfaces[1].ip }}"
101   when: item.hostname == 'yardstickvm'
102   with_items: "{{ infra_deploy_vars.nodes }}"