---
  - name: Bootstap Ansible FreeBSD
    hosts: all
    become: yes
    gather_facts: false
    tasks:
      - name: Setup Sudo and Python3
        raw: pkg install -y sudo python3
        become: no

  - name: Install default packages
    hosts: all
    become: yes
    tasks:
      - name: Installing...
        package: name={{ item }} state=latest
        with_items:
            - sudo
            - python3
            - zsh
            - tmux
            - git


  - name: Set up user environment
    hosts: all
    tasks:
      - name: Cloning dotfiles
        git:
            repo: https://github.com/scruffydan/dotfiles.git
            dest: ~/dotfiles
            clone: yes
            update: yes
            force: yes

      - name: installing config files
        lineinfile:
            path: "{{ item.file }}"
            line: "{{ item.config }}"
            create: yes
        with_items:
           - { file: '~/.zshrc', config: 'source ~/dotfiles/zshrc' }
           - { file: '~/.zshenv', config: 'source ~/dotfiles/zsh/env' }
           - { file: '~/.tmux.conf', config: 'source-file ~/dotfiles/tmux.conf' }
           - { file: '~/.gitconfig', config: '[include]' }
           - { file: '~/.gitconfig', config: "    path = dotfiles/git/gitconfig" }


      - name: change user shell to zsh
        become: yes
        command: chsh -s /usr/local/bin/zsh {{ ansible_user_id }}
