- hosts: localhost
  tasks:

  - name: Add variables to bashrc file for {{ ansible_env.USER }}
    lineinfile: dest=/home/{{ ansible_env.USER }}/.bashrc regexp="{{ item }}" line="{{ item }}" state=present
    with_items:
      - export AWS_DEFAULT_REGION="eu-west-1"
      - export vpc_destination_variable="private_ip_address"

#  - name: Create .bash_aliases file
#    state: present
#    file: path=/home/theodore/.bash_aliases state=touch owner=theodore group=theodore mode=0644

  - name: Create .bash_aliases file
    copy:
      content: ""
      dest: /home/{{ ansible_env.USER }}/.bash_aliases
      force: no
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: 0644

  - name: Add aliases to bashrc file
    lineinfile: dest=/home/{{ ansible_env.USER }}/.bash_aliases regexp="{{ item }}" line="{{ item }}" state=present
    with_items:
      - alias goipt="cd ~/work/home/ipt/shell"
      - alias ptf="cd ~/work/work/tdcs/workspace/PTF"
      - alias sqlplus="~/opt/sqlcl/bin/sql"
      - alias k9s="~/tools/k9s/k9s"

  - name: Install Apt Packages
    become: yes
    apt:
      state: present
      name:
        - terminator
        - awscli
        - ufw
        - clamav
        - resolvconf
        - sshpass
        - openvpn
        - maven
        - dos2unix
        - pandoc
        - highlight
        - exiv2
        - imagemagick
        - texlive-latex-base
        - texlive-latex-extra
        - oathtool

  - name: Copy vault
    become: yes
    copy:
      src: /home/{{ ansible_env.USER }}/tools/vault/vault
      dest: /usr/local/bin/
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no

  - name: Copy GPG
    copy:
      src: ../../ipt/env/dot_gnupg
      dest: /home/{{ ansible_env.USER }}/.gnupg
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      force: no


  - name: Create Terminator dir
    file:
      path: /home/{{ ansible_env.USER }}/.config/terminator
      state: directory
      force: no

  - name: Copy Terminator
    copy:
      src: ../../ipt/env/dotconfig_terminator_config
      dest: /home/{{ ansible_env.USER }}/.config/terminator/config
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0644'
      force: no

#   - name: Install Slack
#    apt:
#      state: present
#      force: no
#      deb: /home/theodore/tools/slack-desktop-4.1.1-amd64.deb

  - name: Flatpak Install Slack
    become: yes
    command: flatpak install --assumeyes flathub com.slack.Slack
    args:
      creates: /home/{{ ansible_env.USER }}/Desktop/com.slack.Slack.desktop

  - name: Copy Slack Desktop files
    copy:
      src: ./Desktop/com.slack.Slack.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/com.slack.Slack.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no

  - name: Install kubeconfig
    become: yes
    get_url:
      url: https://dl.k8s.io/release/v1.18.0/bin/linux/amd64/kubectl
      dest: /usr/local/bin/kubectl
      force: no
      mode: '0755'

#  - name: Setup kubeconfig
#    command: "{{ item }}"
#    with_items:
#      - mkdir ~/.kube
#      - cp  /home/{{ ansible_env.USER }}/work/home/ipt/env/kubectl_202101.cfg ~/.kube/config

  - name: Setup kubeconfig make dir
    file:
      path: /home/{{ ansible_env.USER }}/.kube
      state: directory
      force: no

  - name: Setup kubeconfig copy files
    copy:
      src: ../../ipt/env/kubectl_202101.cfg
      dest: ~/.kube/config
      force: no
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: 0644

  - name: Setup ssh mapping files
    become: yes
    copy:
      src: ./root/etc/ssh/ssh_config
      dest: /etc/ssh/ssh_config
      force: yes
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: 0644

  - name: Setup ssh dir
    file:
      path: /home/{{ ansible_env.USER }}/.ssh
      state: directory
      force: no

  - name: Setup ssh access files
    copy:
      src: ../.ssh/id_rsa
      dest: /home/{{ ansible_env.USER }}/.ssh/id_rsa
      force: no
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: 0600

  - name: Setup ssh access files
    copy:
      src: ../.ssh/id_rsa.pub
      dest: /home/{{ ansible_env.USER }}/.ssh/id_rsa.pub
      force: no
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: 0600

  - name: Flatpak Install DBeaver
    become: yes
    command: flatpak install --assumeyes flathub io.dbeaver.DBeaverCommunity
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/io.dbeaver.DBeaverCommunity

  - name: Flatpak Install Zim
    become: yes
    command: flatpak install --assumeyes flathub org.zim_wiki.Zim
    args:
      creates: /home/{{ ansible_env.USER }}/.var/app/org.zim_wiki.Zim

  - name: Flatpak Install IntelliJ
    become: yes
    command: flatpak install --assumeyes flathub com.jetbrains.IntelliJ-IDEA-Community
    args:
      creates: /home/{{ ansible_env.USER }}/.java/.userPrefs/jetbrains/prefs.xml

  - name: Flatpak Install Visual Studio Code
    become: yes
    command: flatpak install --assumeyes flathub com.visualstudio.code
    args:
      creates: /home/{{ ansible_env.USER }}/Desktop/Visual Studio Code.desktop

  - name: Copy Desktop files
    copy:
      src: ./Desktop/Visual Studio Code.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/Visual Studio Code.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Copy Desktop files
    copy:
      src: ./Desktop/com.jetbrains.IntelliJ-IDEA-Community.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Copy Desktop files
    copy:
      src: ./Desktop/PlantUML.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Set SoapUI run permissions
    file:
      path: /home/{{ ansible_env.USER }}/tools/SmartBear/SoapUI-5.6.0/bin/SoapUI-5.6.0
      mode: u+x
      state: touch
      force: no

  - name: Copy Desktop files
    copy:
      src: ./Desktop/SoapUI 5.6.0.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Set Jmeter3.3 run permissions
    file:
      path: /home/{{ ansible_env.USER }}/tools/apache-jmeter-3.3/bin/jmeter.sh
      mode: u+x
      state: touch
      force: no

  - name: Set Jmeter3.3 run permissions
    file:
      path: /home/{{ ansible_env.USER }}/tools/apache-jmeter-3.3/bin/jmeter
      mode: u+x
      state: touch
      force: no

  - name: Set Jmeter5.3 run permissions
    file:
      path: /home/{{ ansible_env.USER }}/tools/apache-jmeter-5.3/bin/jmeter.sh
      mode: u+x
      state: touch
      force: no

  - name: Set Jmeter5.3 run permissions
    file:
      path: /home/{{ ansible_env.USER }}/tools/apache-jmeter-5.3/bin/jmeter
      mode: u+x
      state: touch
      force: no

  - name: Set sqldeveloper run permissions
    file:
      path: /home/{{ ansible_env.USER }}/opt/sqldeveloper/sqldeveloper.sh
      mode: u+x
      state: touch
      force: no

  - name: Copy Desktop files
    copy:
      src: ./Desktop/JMeter 3.3.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/JMeter 3.3.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Copy Desktop files
    copy:
      src: ./Desktop/JMeter 5.3.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/JMeter 5.3.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Copy Desktop files
    copy:
      src: ./Desktop/sqldeveloper.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Install VeraCrypt
    become: yes
    apt:
      deb: /home/{{ ansible_env.USER }}/tools/veracrypt-1.25.9-Ubuntu-20.04-amd64.deb
    tags:
      - security
      - never


  - name: "Add nodejs apt key"
    become: yes
    apt_key:
      url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
      state: present
    tags:
      - testtools
      - never

  - name: "Add nodejs 14.x ppa for apt repo"
    become: yes
    apt_repository:
      repo: deb https://deb.nodesource.com/node_14.x bionic main
      update_cache: yes
    tags:
      - testtools
      - never

  - name: Install Test Tools
    become: yes
    apt:
      state: present
      name:
        - nodejs
        - nmap
    tags:
      - testtools
      - never

  - name: Add UPM repo
    become: yes
    apt_repository:
      validate_certs: yes
      repo: 'ppa:adriansmith/upm'
      state: present
    tags:
      - not19versupm
      - never

  - name: Install UPM
    become: yes
    apt:
      state: present
      update_cache: no
      name:
        - upm
    tags:
      - not19versupm
      - never


  - name: Install UPM
    become: yes
    apt:
      deb: https://launchpad.net/~adriansmith/+archive/ubuntu/upm/+files/upm_1.14-1~ppa3_all.deb
    tags:
      - upm
      - never

  - name: Set upm run permissions
    file:
      path: ~/tools/upm-1.15.1/upm.sh
      mode: u+x
      state: touch
      force: no
    tags:
      - upmlocal
      - never

  - name: Copy upm config
    copy:
      src: ./dot_config/upm.properties
      dest: ~/.config/upm.properties
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0664'
      force: no
    tags:
      - upmlocal
      - never

  - name: Copy Desktop files
    copy:
      src: ./Desktop/upm.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/upm.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - upmlocal
      - desktop
      - never

  - name: Install bruno
    become: yes
    apt:
      deb: https://github.com/usebruno/bruno/releases/download/v1.9.0/bruno_1.9.0_amd64_linux.deb
    tags:
      - bruno
      - never
