---
# Install kvm
# sudo dnf -y install bridge-utils libvirt virt-install qemu-kvm virt-manager
# sudo systemctl start libvirtd
# Install developer tools
- name: Ensure common developer tools installed
  dnf:
    name: 
    - vim-enhanced
    - iperf3
    - python3-pip
    - glances
    - htop
    - dconf-editor
    - dnf-plugins-core
  become: yes
# Install snap developer tools
- name: Ensure snap installed
  dnf:
    name: snapd
    state: present
  become: yes
- name: Link /var/lib/snapd/snap /snap
  ansible.builtin.file:
    src: /var/lib/snapd/snap
    dest: /snap
    owner: root
    group: root
    state: link
  become: yes
- name: Ensure snapd service running
  ansible.builtin.systemd:
    name: snapd.socket
    state: started
    enabled: yes
  become: yes
- name: Install snap packages
  community.general.snap:
    name: 
    - yq
    state: present
  become: yes
- name: Install classic snap packages
  community.general.snap:
    name:
    - code
    - kubectl
    - helm
    state: present
    classic: yes
  become: yes
# AWS CLI
- name: Download awscli v2 installer - latest version
  unarchive:
    src: https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
    dest: '{{ executable_temp_dir }}'
    remote_src: true
    creates: '{{ executable_temp_dir }}/aws'
    mode: 0755
  when: awscli_version is not defined
  tags: ["awscli", "awscliv2"]
- name: Download awscli v2 installer - specific version {{ awscli_version }}
  unarchive:
    src: 'https://awscli.amazonaws.com/awscli-exe-linux-x86_64-{{ awscli_version }}.zip'
    dest: "{{ executable_temp_dir }}"
    remote_src: true
    creates: '{{ executable_temp_dir }}/aws'
    mode: 0755
  when: awscli_version is defined
  tags: ["awscli", "awscliv2"]
- name: Run the installer for awscli v2
  command:
  args:
    cmd: '{{ executable_temp_dir }}/aws/install -i {{ awscli_install_dir }} -b /usr/local/bin'
    creates: /usr/local/bin/aws
  become: yes
  tags: ["awscli", "awscliv2"]
# Ansible
- name: Install ansible
  pip:
    name: ansible
    extra_args: --user
# Docker
- name: Add Docker dnf repo
  command: dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
  become: yes
- name: Ensure Docker installed
  dnf:
    name: 
    - docker-ce
    - docker-ce-cli
    - containerd.io
    state: present
  become: yes
- name: Ensure ducoterra in the "docker" group
  ansible.builtin.user:
    name: ducoterra
    groups: docker
    append: yes
  become: yes
# Vault CLI
- name: Download vault binary
  unarchive:
    src: https://releases.hashicorp.com/vault/{{vault_version}}/vault_{{vault_version}}_linux_amd64.zip
    dest: '{{ executable_temp_dir }}'
    remote_src: true
    creates: '{{ executable_temp_dir }}/vault'
    mode: 0755
  become: yes
- name: Move vault binary to /usr/local/bin
  ansible.builtin.copy:
    remote_src: yes
    src: '{{ executable_temp_dir }}/vault'
    dest: /usr/local/bin/vault
    owner: root
    group: root
    mode: '0755'
  become: yes
# Terraform CLI
- name: Download vault binary
  unarchive:
    src: https://releases.hashicorp.com/terraform/{{tf_version}}/terraform_{{tf_version}}_linux_amd64.zip
    dest: '{{ executable_temp_dir }}'
    remote_src: true
    creates: '{{ executable_temp_dir }}/terraform'
    mode: 0755
  become: yes
- name: Move terraform binary to /usr/local/bin
  ansible.builtin.copy:
    remote_src: yes
    src: '{{ executable_temp_dir }}/terraform'
    dest: /usr/local/bin/terraform
    owner: root
    group: root
    mode: '0755'
  become: yes
# Packer CLI
- name: Download packer binary
  unarchive:
    src: https://releases.hashicorp.com/packer/{{packer_version}}/packer_{{packer_version}}_linux_amd64.zip
    dest: '{{ executable_temp_dir }}'
    remote_src: true
    creates: '{{ executable_temp_dir }}/packer'
    mode: 0755
  become: yes
- name: Move packer binary to /usr/local/bin
  ansible.builtin.copy:
    remote_src: yes
    src: '{{ executable_temp_dir }}/packer'
    dest: /usr/local/bin/packer
    owner: root
    group: root
    mode: '0755'
  become: yes
# Wireguard Configuration
- name: Ensure wireguard-tools installed
  dnf:
    name:  wireguard-tools
    state: present
  become: yes
- name: Ensure /etc/wireguard directory
  file:
    path: /etc/wireguard
    state: directory
  become: yes
