---
- name: Ensure GitHub host key is in known_hosts
  known_hosts:
    path: "~/.ssh/known_hosts"
    name: github.com
    key: "{{ lookup('pipe', 'ssh-keyscan -t ed25519 github.com | grep -v \"^#\"') }}"
  become: yes

- name: Create installation directory for Kevin's Package Manager
  file:
    path: "{{ pkgmgr_install_path }}"
    state: directory
    mode: '0755'
  become: yes
  when: run_once_package_manager is not defined

- name: Clone Kevin's Package Manager repository
  git:
    repo: "{{ pkgmgr_repo_url }}"
    dest: "{{ pkgmgr_install_path }}"
    version: "HEAD"
    force: yes
  become: yes
  when: run_once_package_manager is not defined

- name: Ensure main.py is executable
  file:
    path: "{{ pkgmgr_install_path }}/main.py"
    mode: '0755'
  become: yes
  when: run_once_package_manager is not defined

- name: create config.yaml
  template: 
    src: config.yaml.j2
    dest: "{{pkgmgr_config_path}}"
  become: yes
  when: run_once_package_manager is not defined

- name: Run the Package Manager install command to create an alias for Kevins package manager
  shell: |
    source ~/.venvs/pkgmgr/bin/activate
    make setup
  args:
    chdir: "{{ pkgmgr_install_path }}"
    executable: /bin/bash
  become: yes
  when: run_once_package_manager is not defined

- name: run run_once_package_manager tasks once
  set_fact:
    run_once_package_managerr: true
  when: run_once_package_manager is not defined