---
# This Ansible role adds a super user {{ USERNAME }}, sets automatic login
# if LXDM is installed, and sets automatic login on boot if desired.
- name: Add the user.
  user:
    name={{ USERNAME }}
    password={{ PASSWORD }}
    state=present
    groups=sudo,adm
  sudo: yes

- name: Determine if a user has been configured to log in automatically.
  command: grep "exec /sbin/getty -8 38400 tty1" /etc/init/tty1.conf -c
  register: auto_log_set

- name: Set automatic console login for this user if desired. Only works once.
  lineinfile:
    dest=/etc/init/tty1.conf
    create=yes
    regexp="exec /sbin/getty -8 38400 tty1"
    line="exec /bin/login -f {{ USERNAME }} < /dev/tty1 > /dev/tty1 2>&1"
  sudo: yes
  when: (auto_log_set.stdout.find('0') != 1 and {{ AUTOLOGIN }} == "true")

- name: Determine if LXDM is installed.
  command: dpkg-query -l lxdm
  register: query_lxdm

- name: Set this as the default user if LXDM is installed.
  lineinfile:
    dest=/etc/lxdm/lxdm.conf
    create=yes
    regexp="^(# )?autologin.*="
    line="autologin=vagrant"
  sudo: yes
  when: query_lxdm.stdout.find('no packages found') != -1
---
# This Ansible role adds a super user {{ USERNAME }}, sets automatic login
# if LXDM is installed, and sets automatic login on boot if desired.
- name: Add the user.
  user:
    name={{ USERNAME }}
    password={{ PASSWORD }}
    state=present
    groups=sudo,adm
  sudo: yes

- name: Determine if a user has already been configured to login automatically.
  shell: grep "exec /sbin/getty -8 38400 tty1" /etc/init/tty1.conf -c
  register: auto_log_set
  ignore_errors: true

- name: Set automatic console login for this user if desired. Only works once.
  lineinfile:
    dest=/etc/init/tty1.conf
    create=yes
    regexp="exec /sbin/getty -8 38400 tty1"
    line="exec /bin/login -f {{ USERNAME }} < /dev/tty1 > /dev/tty1 2>&1"
  sudo: yes
  when: auto_log_set.stdout.find('1') != -1 and {{ AUTOLOGIN }} == true

- name: Determine if LXDM is installed.
  command: dpkg-query -l lxdm
  register: query_lxdm

- name: Set this as the default user if LXDM is installed.
  lineinfile:
    dest=/etc/lxdm/lxdm.conf
    create=yes
    regexp="^(# )?autologin.*="
    line="autologin=vagrant"
  sudo: yes
  when: query_lxdm.stdout.find('no packages found') != -1
Fix mistakes with automatic login through console.
Fix mistakes with automatic login through console.
