blob: 73830663c77df26322612fe451a9e5d23ccff18f (
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
---
- name: Prepare infrastructure and create operation instances
hosts: localhost
connection: local
gather_facts: False
roles:
- create_network
- create_securitygroup
- create_keypair
- role: create_hosts
hosts: "{{ operation.hosts }}"
operator_key: "dummy"
tasks:
- name: Get operator Openstack info
openstack.cloud.server_info:
server: "operator0"
register: operator_info
- name: Create directory for artifacts
ansible.builtin.file:
name: "artifacts"
state: directory
mode: '0755'
- name: Save operator access information
ansible.builtin.copy:
content: "{{ operator_info['openstack_servers'][0]['public_v4'] }},{{ image['user'] }},~/.ssh/{{ keypair['key']['name'] }}"
dest: "artifacts/operator.csv"
mode: "0644"
- name: Create cluster operator access keypair
hosts: "operator0"
gather_facts: False
tasks:
- name: Wait for system to become reachable
wait_for_connection:
- name: Generate an OpenSSH keypair with the default values (4096 bits, rsa)
community.crypto.openssh_keypair:
path: "~/.ssh/{{ keypair.name }}"
register: key
- name: Add operator0 public key to it's authorized keys
ansible.posix.authorized_key:
key: "{{ key['public_key'] }}"
state: present
user: "{{ ansible_user }}"
- name: Create OpenStack instances
hosts: localhost
connection: local
gather_facts: False
roles:
- role: create_hosts
hosts: "{{ openstack.hosts }}"
operator_key: "{{ hostvars['operator0']['key']['public_key'] }}"
- name: Create cluster instances
hosts: localhost
connection: local
gather_facts: False
roles:
- role: create_hosts
hosts: "{{ cluster.hosts }}"
operator_key: "{{ hostvars['operator0']['key']['public_key'] }}"
- name: Create cluster operator access information
hosts: "operator0"
vars_files:
- ../../common-vars.yml
tasks:
- name: Add cluster hostnames to /etc/hosts file
lineinfile:
path: /etc/hosts
line: "{{ item.value + ' ' + item.key }}"
become: yes
loop: "{{ lookup('dict', hostvars['localhost']['hosts_dict']) }}"
- name: Create inventory for in-cluster deployment stage
template:
src: templates/inventory.ini.j2
dest: "{{ operation.inventory }}"
vars:
hosts: "{{ lookup('dict', hostvars['localhost']['hosts_dict']) }}"
- name: Push in-cluster deployment stage description to the next Ansible control host
copy:
src: ../../cluster-rke
dest: ~/deploy
- name: Push Devstack deployment stage description to the next Ansible control host
copy:
src: ../../devstack
dest: ~/
- name: Push common variables to the next Ansible control host
copy:
src: ../../common-vars.yml
dest: ~/
- name: Push Devstack vars to the next Ansible control host (for Devstack stage)
template:
src: "templates/openstack.yml.j2"
dest: ~/devstack/ansible/group_vars/all/openstack.yml
mode: '0644'
- name: Push Devstack vars to the next Ansible control host (for cluster-rke stage)
template:
src: "templates/openstack.yml.j2"
dest: ~/deploy/cluster-rke/ansible/group_vars/all/openstack.yml
mode: '0644'
- name: Create Devstack config directory
file:
path: ~/.config/openstack/
state: directory
mode: '0755'
- name: Generate Devstack clouds.yml file
template:
src: "templates/clouds.yaml.j2"
dest: ~/.config/openstack/clouds.yml
mode: '0644'
- block:
- name: Install python dependencies
become: yes
apt:
name:
- python3-pip
- python3-setuptools
- default-jdk-headless
state: present
update_cache: true
- name: Install community.kubernetes.k8s Ansible collection dependencies
pip:
name:
- ansible-core==2.13.5
- openshift==0.13.1
- pyyaml==6.0
# Major version of Python k8s libraty matches minor version of k8s.
- kubernetes~={{ k8s_version | regex_search("[^^.][0-9]+[^$]") ~ "0" }}
executable: pip3
become: yes
- name: Copy ansible-galaxy requirements file
copy:
src: operator-requirements.yml
dest: ~/requirements.yml
mode: '0444'
- name: Install ansible-galaxy collections
community.general.ansible_galaxy_install:
requirements_file: ~/requirements.yml
type: both
|