- name: common-users-setup-account
  user:
    name: "{{ item.name }}"
    state: present
    skeleton: /etc/skel
    shell: /bin/bash
    system: no
    createhome: yes
    home: "/home/{{ item.name }}"
  register: new_user

- name: common-users-setup-sudo
  user:
    name: "{{ item.name }}"
    group: sudo
  when: item.sudo|default(false) == true

- name: common-users-setup-key
  authorized_key:
    user: "{{ item.name }}"
    state: present
    key: "{{ item.key }}"

- name: common-users-setup-onion
  template:
    src: ../../files/onion.conf.j2
    dest: "/etc/tor/onions/{{ item.name }}.conf"

- name: common-users-setup-irc
  irc:
    msg: "{{ irc_announce.msg | default('Bienvenue à ' ~ item.name ~ sur le serveur \\o/') }}"
    server: "{{ irc_announce.server | default('irc.tilde.chat') }}"
    port: "{{ irc_announce.port | default(6697) }}"
    channel: "{{ irc_announce.chan }}"
    nick: "{{ irc_announce.nick | default('ansibot') }}"
    nick_to: "{{ irc_announce.query | default([]) }}"
    use_ssl: "{{ irc_announce.tls | default(true) }}"
    timeout: "{{ irc_announce.timeout | default(10) }}"
  when: new_user.changed and irc_announce is defined
