- include_role:
    name: per_user

- name: Create directories
  file:
    name: "{{ account_homedir.stdout }}/{{ item }}"
    state: directory
    mode: 0700
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
  loop:
    - ".ssh"

- name: Add ssh hosts to config
  blockinfile:
    path: "{{ account_homedir.stdout }}/.ssh/config"
    marker: "# {mark} ANSIBLE MANAGED BLOCK {{ item.name }}"
    create: true
    mode: 0600
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
    block: |
      Host {{ item.name }}
      {% if item.proxy_jump is defined %}
        ProxyJump {{ item.proxy_jump }}
      {% endif %}
      {% if item.host_name is defined %}
        HostName {{ item.host_name }}
      {% endif %}
  when: ssh_hosts is defined
  loop: "{{ ssh_hosts }}"

- name: Compress all SSH connections by default
  blockinfile:
    path: "{{ account_homedir.stdout }}/.ssh/config"
    marker: "# {mark} ANSIBLE MANAGED BLOCK compression"
    create: true
    mode: 0600
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
    block: |
      Host *
        Compression yes

- import_tasks: tasks/peruser_freebsd.yaml
  when: 'os_flavor == "freebsd"'

- import_tasks: tasks/peruser_linux.yaml
  when: 'os_flavor == "linux"'