infra/ansible/roles/uisp/tasks/main.yml

139 lines
3.4 KiB
YAML

---
- name: Install Docker prerequisites
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
state: present
update_cache: yes
- name: Add Docker GPG key
ansible.builtin.get_url:
url: https://download.docker.com/linux/debian/gpg
dest: /etc/apt/keyrings/docker.asc
mode: '0644'
- name: Add Docker APT repository
ansible.builtin.deb822_repository:
name: docker
types: [deb]
uris: https://download.docker.com/linux/debian
suites: "{{ ansible_facts['distribution_release'] }}"
components: [stable]
architectures: [amd64]
signed_by: /etc/apt/keyrings/docker.asc
state: present
- name: Remove legacy Docker .list repo (superseded by deb822 .sources)
ansible.builtin.file:
path: /etc/apt/sources.list.d/docker.list
state: absent
- name: Install Docker CE
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
- docker-ce-rootless-extras
state: present
update_cache: yes
- name: Create UISP group
ansible.builtin.group:
name: "{{ uisp_group }}"
gid: "{{ uisp_group_gid }}"
state: present
- name: Create UISP user
ansible.builtin.user:
name: "{{ uisp_user }}"
uid: "{{ uisp_user_uid }}"
group: "{{ uisp_group }}"
groups: docker
append: yes
home: "{{ uisp_home }}"
shell: /bin/sh
state: present
- name: Ensure Docker is running
ansible.builtin.systemd:
name: docker
state: started
enabled: yes
- name: Create containerd killmode override directory
ansible.builtin.file:
path: /usr/lib/systemd/system/containerd.service.d
state: directory
owner: root
group: root
mode: '0755'
- name: Configure containerd KillMode for UISP
ansible.builtin.copy:
dest: /usr/lib/systemd/system/containerd.service.d/unms-killmode.conf
content: |
[Service]
KillMode=mixed
owner: root
group: root
mode: '0644'
notify:
- Reload systemd
- Restart containerd
- name: Ensure UISP app directory exists
ansible.builtin.file:
path: "{{ uisp_app_dir }}"
state: directory
owner: "{{ uisp_user }}"
group: root
mode: '0700'
- name: Ensure UISP data directory exists
ansible.builtin.file:
path: "{{ uisp_data_dir }}"
state: directory
owner: "{{ uisp_user }}"
group: root
mode: '0700'
- name: Download UISP installer script
ansible.builtin.get_url:
url: https://uisp.ui.com/install
dest: "{{ uisp_app_dir }}/update.sh"
owner: "{{ uisp_user }}"
group: root
mode: "0755"
register: uisp_installer
- name: Check if UISP containers are already running
community.docker.docker_container_info:
name: unms-postgres
register: uisp_postgres_container
failed_when: false
- name: Run UISP installer (first install only — skips existing)
ansible.builtin.command: "{{ uisp_app_dir }}/update.sh --update"
become: true
become_user: "{{ uisp_user }}"
environment:
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
when:
- not uisp_postgres_container.exists | default(false)
register: uisp_install
changed_when: uisp_install.rc == 0
- name: Deploy UISP auto-update cron job
ansible.builtin.copy:
dest: /etc/cron.d/unms-update
content: |
* * * * * {{ uisp_user }} {{ uisp_app_dir }}/update.sh --update > /dev/null 2>&1 || true
owner: root
group: root
mode: '0644'