- /inventories/group_vars/all.yml - /inventories/group_vars/gateway.yml - /roles/npm/tasks/main.yml - /roles/heimdall/tasks/main.yml - /roles/docker/tasks/main.yml - /group_vars/all.yml - /group_vars/gateway_servers.yml - /roles/proxmox_lxc/handlers/main.yml - /roles/proxmox_lxc/tasks/main.yml - /roles/gateway/handlers/main.yml - /roles/gateway/tasks/main.yml - /gateway-deploy.yml - /olimp-deploy.yml
73 lines
2.1 KiB
YAML
73 lines
2.1 KiB
YAML
---
|
|
- name: Check if container already exists
|
|
shell: pct list | grep "{{ item.vmid }}" || true
|
|
register: container_check
|
|
delegate_to: proxmox
|
|
loop: "{{ containers }}"
|
|
loop_control:
|
|
label: "{{ item.hostname }}"
|
|
|
|
- name: Create temporary SSH keys file on Proxmox
|
|
copy:
|
|
content: "{{ ssh_public_keys | join('\n') }}"
|
|
dest: "/tmp/ssh_keys_{{ item.vmid }}.txt"
|
|
mode: '0644'
|
|
delegate_to: proxmox
|
|
loop: "{{ containers }}"
|
|
when: "item.vmid not in container_check.results[0].stdout"
|
|
loop_control:
|
|
label: "{{ item.hostname }}"
|
|
|
|
- name: Create LXC containers
|
|
shell: |
|
|
pct create {{ item.vmid }} \
|
|
"{{ item.template_path }}" \
|
|
--rootfs {{ item.storage }}:{{ item.disk_size }} \
|
|
--cores {{ item.cores }} \
|
|
--memory {{ item.memory }} \
|
|
--swap {{ item.swap }} \
|
|
--hostname {{ item.hostname }} \
|
|
--net0 name=eth0,bridge=vmbr0,ip={{ item.ip }}/24,gw=192.168.1.1 \
|
|
--storage {{ item.storage }} \
|
|
--password "{{ proxmox_root_password }}" \
|
|
--unprivileged 0 \
|
|
--features nesting=1 \
|
|
--ssh-public-keys /tmp/ssh_keys_{{ item.vmid }}.txt \
|
|
--start 1
|
|
args:
|
|
executable: /bin/bash
|
|
delegate_to: proxmox
|
|
loop: "{{ containers }}"
|
|
when: "item.vmid not in container_check.results[0].stdout"
|
|
loop_control:
|
|
label: "{{ item.hostname }}"
|
|
|
|
- name: Remove temporary SSH keys files
|
|
file:
|
|
path: "/tmp/ssh_keys_{{ item.vmid }}.txt"
|
|
state: absent
|
|
delegate_to: proxmox
|
|
loop: "{{ containers }}"
|
|
loop_control:
|
|
label: "{{ item.hostname }}"
|
|
|
|
- name: Configure LXC for Docker support
|
|
shell: |
|
|
pct set {{ item.vmid }} -lxc.apparmor.profile=unconfined
|
|
pct set {{ item.vmid }} -lxc.cgroup.devices.allow=a
|
|
pct set {{ item.vmid }} -lxc.cap.drop=
|
|
delegate_to: proxmox
|
|
loop: "{{ containers }}"
|
|
loop_control:
|
|
label: "{{ item.hostname }}"
|
|
|
|
- name: Wait for containers to be ready
|
|
wait_for:
|
|
host: "{{ item.ip }}"
|
|
port: 22
|
|
timeout: 120
|
|
delay: 10
|
|
delegate_to: localhost
|
|
loop: "{{ containers }}"
|
|
loop_control:
|
|
label: "{{ item.hostname }}" |