---
# tasks file for openbsd-bootstrap

- name: Check if sudo is available
  raw: 'which sudo > /dev/null 2>/dev/null && echo sudo || echo doas'
  changed_when: False
  become: False
  register: openbsd_bootstrap_check_sudo
  check_mode: False

- name: Install Python
  raw: "PKG_PATH={{ openbsd_pkg_mirror }}/OpenBSD/$(uname -r)/packages/$(arch -s)/ /usr/sbin/pkg_add -Iz python-2.7"
  register: openbsd_pkg_add_python
  failed_when: "'error' in openbsd_pkg_add_python.stdout|lower"
  changed_when: "'py-pip' in openbsd_pkg_add_python.stdout"
  tags:
      - skip_ansible_lint

- name: Gather facts
  setup:

- name: Symlink python
  with_items:
      - /usr/bin/python
      - /usr/local/bin/python2
  ignore_errors: '{{ ansible_check_mode }}'
  file:
      path: '{{ item }}'
      src: /usr/local/bin/python2.7
      state: link
      owner: root
      group: wheel
      mode: 0o0755

- name: Configure pkg
  lineinfile:
    dest: /etc/pkg.conf
    line: 'installpath = {{ openbsd_pkg_mirror }}/OpenBSD/{{ ansible_distribution_release }}/packages/{{ ansible_architecture }}/'
    regexp: '^installpath ='
    state: present
    create: yes
