noheat: Upgrades, refactor, deploy Devstack
[integration.git] / deployment / noheat / infra-openstack / ansible / create.yml
1 ---
2 - name: Prepare infrastructure and create operation instances
3   hosts: localhost
4   connection: local
5   gather_facts: False
6   roles:
7     - create_network
8     - create_securitygroup
9     - create_keypair
10     - role: create_hosts
11       hosts: "{{ operation.hosts }}"
12       operator_key: "dummy"
13   tasks:
14     - name: Get operator Openstack info
15       openstack.cloud.server_info:
16         server: "operator0"
17       register: operator_info
18     - name: Create directory for artifacts
19       ansible.builtin.file:
20         name: "artifacts"
21         state: directory
22         mode: '0755'
23     - name: Save operator access information
24       ansible.builtin.copy:
25         content: "{{ operator_info['openstack_servers'][0]['public_v4'] }},{{ image['user'] }},~/.ssh/{{ keypair['key']['name'] }}"
26         dest: "artifacts/operator.csv"
27         mode: "0644"
28 - name: Create cluster operator access keypair
29   hosts: "operator0"
30   gather_facts: False
31   tasks:
32     - name: Wait for system to become reachable
33       wait_for_connection:
34     - name: Generate an OpenSSH keypair with the default values (4096 bits, rsa)
35       community.crypto.openssh_keypair:
36         path: "~/.ssh/{{ keypair.name }}"
37       register: key
38     - name: Add operator0 public key to it's authorized keys
39       ansible.posix.authorized_key:
40         key: "{{ key['public_key'] }}"
41         state: present
42         user: "{{ ansible_user }}"
43 - name: Create OpenStack instances
44   hosts: localhost
45   connection: local
46   gather_facts: False
47   roles:
48     - role: create_hosts
49       hosts: "{{ openstack.hosts }}"
50       operator_key: "{{ hostvars['operator0']['key']['public_key'] }}"
51 - name: Create cluster instances
52   hosts: localhost
53   connection: local
54   gather_facts: False
55   roles:
56     - role: create_hosts
57       hosts: "{{ cluster.hosts }}"
58       operator_key: "{{ hostvars['operator0']['key']['public_key'] }}"
59 - name: Create cluster operator access information
60   hosts: "operator0"
61   vars_files:
62     - ../../common-vars.yml
63   tasks:
64     - name: Add cluster hostnames to /etc/hosts file
65       lineinfile:
66         path: /etc/hosts
67         line: "{{ item.value + ' ' + item.key }}"
68       become: yes
69       loop: "{{ lookup('dict', hostvars['localhost']['hosts_dict']) }}"
70     - name: Create inventory for in-cluster deployment stage
71       template:
72         src: templates/inventory.ini.j2
73         dest: "{{ operation.inventory }}"
74       vars:
75         hosts: "{{ lookup('dict', hostvars['localhost']['hosts_dict']) }}"
76     - name: Push in-cluster deployment stage description to the next Ansible control host
77       copy:
78         src: ../../cluster-rke
79         dest: ~/deploy
80     - name: Push Devstack deployment stage description to the next Ansible control host
81       copy:
82         src: ../../devstack
83         dest: ~/
84     - name: Push common variables to the next Ansible control host
85       copy:
86         src: ../../common-vars.yml
87         dest: ~/
88     - name: Push Devstack vars to the next Ansible control host (for Devstack stage)
89       template:
90         src: "templates/openstack.yml.j2"
91         dest: ~/devstack/ansible/group_vars/all/openstack.yml
92         mode: '0644'
93     - name: Push Devstack vars to the next Ansible control host (for cluster-rke stage)
94       template:
95         src: "templates/openstack.yml.j2"
96         dest: ~/deploy/cluster-rke/ansible/group_vars/all/openstack.yml
97         mode: '0644'
98     - name: Create Devstack config directory
99       file:
100         path: ~/.config/openstack/
101         state: directory
102         mode: '0755'
103     - name: Generate Devstack clouds.yml file
104       template:
105         src: "templates/clouds.yaml.j2"
106         dest: ~/.config/openstack/clouds.yml
107         mode: '0644'
108     - block:
109       - name: Install python dependencies
110         become: yes
111         apt:
112           name:
113             - python3-pip
114             - python3-setuptools
115             - default-jdk-headless
116           state: present
117           update_cache: true
118       - name: Install community.kubernetes.k8s Ansible collection dependencies
119         pip:
120           name:
121             - ansible-core==2.13.5
122             - openshift==0.13.1
123             - pyyaml==6.0
124             # Major version of Python k8s libraty matches minor version of k8s.
125             - kubernetes~={{ k8s_version | regex_search("[^^.][0-9]+[^$]") ~ "0" }}
126           executable: pip3
127         become: yes
128       - name: Copy ansible-galaxy requirements file
129         copy:
130           src: operator-requirements.yml
131           dest: ~/requirements.yml
132           mode: '0444'
133       - name: Install ansible-galaxy collections
134         community.general.ansible_galaxy_install:
135           requirements_file: ~/requirements.yml
136           type: both