--- - hosts: service remote_user: "{{ user }}" gather_facts: no vars: user: "zeus" tasks: - name: Create a login user become: true user: name: "{{ ruser }}" password: "{{ rpassword }}" groups: # Empty by default, here we give it some groups - sudo state: present shell: /bin/bash # Defaults to /bin/bash system: no # Defaults to no createhome: yes # Defaults to yes home: "/home/{{ ruser }}" # Defaults to /home/ - name: Creates directory .ssh become: true file: path: "/home/{{ ruser }}/.ssh" state: directory owner: "{{ ruser }}" group: "{{ ruser }}" mode: 0700 recurse: yes - name: copy auth file authorized_keys become: true copy: src: ../files/authorized_keys dest: "/home/{{ ruser }}/.ssh/authorized_keys" owner: "{{ ruser }}" group: "{{ ruser }}" mode: 0644