Skip to content
Snippets Groups Projects
main.yml 681 B
- name: make /local_home
  file: path=/local_home owner=root group=root state=directory
  sudo: true 

- name: stat the local_home path
  stat: path=/local_home/{{ ansible_user }}
  register: local_home_path

- name: copy the {{ ansible_user }} home
  shell: cp -ar /home/{{ ansible_user }} /local_home
  ignore_errors: true
  sudo: true
  register: home_copied
  when: not local_home_path.stat.exists


- name: edit passwd file
  lineinfile:
  args:
    dest: /etc/passwd
    regexp: '{{ ansible_user }}:x:(.*):(.*):(.*):/home/{{ ansible_user }}:(.*)'
    line: '{{ ansible_user }}:x:\1:\2:\3:/local_home/{{ ansible_user }}:\4'
    backrefs: yes
  sudo: true
  register: edit