---
# file: roles/incus/tasks/scripts.yml

- name: "pip upgrade pip in virtualenv"
  ansible.builtin.pip:
    name: pip
    extra_args: --upgrade
    virtualenv: /usr/local/venvs/init_container
    virtualenv_command: /usr/bin/python3 -m venv
  when: not ansible_check_mode

- name: "pip install dependencies in virtualenv"
  ansible.builtin.pip:
    name:
      - "urllib3{{ general_urllib3_version }}"
      - "pylxd=={{ general_pylxd_version }}"
    extra_args: --upgrade
    virtualenv: /usr/local/venvs/init_container
    virtualenv_command: /usr/bin/python3 -m venv
  when: not ansible_check_mode

- name: "/usr/local/venvs/init_container/bin/init_container.py"
  ansible.builtin.copy:
    src: init_container.py
    dest: /usr/local/venvs/init_container/bin/init_container.py
    mode: 0755

- name: "ln -s /usr/local/venvs/init_container/bin/init_container.py /usr/local/sbin/init_container.py"
  ansible.builtin.file:
    state: link
    src: /usr/local/venvs/init_container/bin/init_container.py
    dest: /usr/local/sbin/init_container.py
    force: true
