-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-with-virt-lightning.yml
200 lines (174 loc) · 5.74 KB
/
main-with-virt-lightning.yml
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
---
- hosts: virtual_machines
gather_facts: true
tasks:
- name: Ensure required packages are installed
ansible.builtin.apt:
name:
- git
- zsh
- wget
state: present
update_cache: true
become: true
- name: Ensure qemu-system-x86 is installed if architecture is x86_64
ansible.builtin.apt:
name: qemu-system-x86
state: present
become: true
when: ansible_facts['architecture'] == 'x86_64'
- name: Ensure qemu-system-arm is installed if architecture is aarch64
ansible.builtin.apt:
name: qemu-system-arm
state: present
become: true
when: ansible_facts['architecture'] == 'aarch64'
- name: Ensure libvirtd/qemu and vm management packages are installed
ansible.builtin.apt:
name:
- libvirt-daemon-driver-qemu
- libvirt-daemon-system
- libvirt-clients
- bridge-utils
- virtinst
- libosinfo-bin
- virt-manager
state: present
update_cache: true
become: true
- name: Ensure the libvirtd service is available
ansible.builtin.service:
name: libvirtd
state: started
enabled: true
- name: Display all IPv4 addresses
ansible.builtin.debug:
var: ansible_facts['all_ipv4_addresses']
- name: Install packages to allow apt to use a repository over HTTPS to allow Docker to be installed
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
state: present
update_cache: true
- name: Add Docker GPG apt Key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker Repository
ansible.builtin.apt_repository:
repo: "deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
- name: Update apt and install docker-ce
ansible.builtin.apt:
name: docker-ce
state: latest
update_cache: true
- name: Install Docker Module for Python
ansible.builtin.pip:
name: docker
state: absent
- name: Ensure Docker service is running and enabled
ansible.builtin.service:
name: docker
state: started
enabled: true
- name: Ensure virt-lightning and its requirements are installed
ansible.builtin.apt:
name:
- python3-pip
- python3-venv
- pkg-config
- gcc
- libvirt-dev
- python3-dev
state: present
update_cache: true
- name: Ensure pipx is installed for Python package isolation
ansible.builtin.pip:
name: pipx
executable: pip3
- name: Ensure pipx bin directory is in the PATH for bash
ansible.builtin.lineinfile:
path: ~/.bashrc
line: 'export PATH=$PATH:~/.local/bin'
create: true
state: present
regexp: '^export PATH=.*~/.local/bin.*$'
become: false
when: ansible_env.SUDO_USER is defined or ansible_env.USER is defined
- name: Ensure pipx bin directory is in the PATH for zsh
ansible.builtin.lineinfile:
path: ~/.zshrc
line: 'export PATH=$PATH:~/.local/bin'
create: yes
state: present
regexp: '^export PATH=.*~/.local/bin.*$'
become: false
when: ansible_env.SUDO_USER is defined or ansible_env.USER is defined
- name: Ensure pipx path is in .bashrc
ansible.builtin.shell: grep -q '~/.local/bin' ~/.bashrc
register: bashrc_check
failed_when: false
changed_when: false
- name: Ensure pipx path is in .zshrc
ansible.builtin.shell: grep -q '~/.local/bin' ~/.zshrc
register: zshrc_check
failed_when: false
changed_when: false
- name: Ensure pipx is initialized (pipx ensurepath)
ansible.builtin.shell: pipx ensurepath
become: false
environment:
PATH: "{{ ansible_env.PATH }}:~/.local/bin"
when: bashrc_check.rc != 0 or zshrc_check.rc != 0
- name: Make pipx_list to search for virt-lightning
ansible.builtin.command: pipx list
register: pipx_list
changed_when: false
- name: Ensure virt-lightning is installed using pipx
ansible.builtin.shell: pipx install virt-lightning
environment:
PATH: "{{ ansible_env.PATH }}:~/.local/bin"
when: "'virt-lightning' not in pipx_list.stdout"
- name: Ensure virt-lightning directories exist
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
mode: '0775'
loop:
- { path: /var/lib/virt-lightning }
- { path: /var/lib/virt-lightning/pool }
- { path: /var/lib/virt-lightning/pool/upstream }
become: true
- name: Set ownership for /var/lib/virt-lightning/pool
ansible.builtin.file:
path: /var/lib/virt-lightning/pool
state: directory
owner: libvirt-qemu
group: kvm
recurse: yes
become: true
- name: Set ownership for /var/lib/virt-lightning/pool/upstream
ansible.builtin.file:
path: /var/lib/virt-lightning/pool/upstream
state: directory
owner: tool
group: tool
recurse: yes
become: true
- name: Link ~/.local/bin/vl to /usr/local/bin/vl
ansible.builtin.file:
src: "~/.local/bin/vl"
dest: "/usr/local/bin/vl"
state: link
force: yes
become: true
- name: Make list of distros available with virt-lightning
ansible.builtin.shell: 'vl distro_list'
register: vl_distro_list