1
votes

I'm using Vagrant (Virtual Box provider) to setup a local Virtual Machine. I'm also using ansible and more specific ansible_local (Vagrant plugin) to deploy some tools into the VM.

Initially I'm trying to create a new user following the ansible documentation.

---
- name: Master Node
hosts: 127.0.0.1
connection: local
user: root
vars_files:
    - vars/vars.yml
vars:
    username: nikolas

tasks:
- name: Adding user
  user: name={{username}} shell=/bin/bash groups=root append=yes password={{pass}}
  sudo: yes

- name: Placing RSA key
  authorized_key: user={{username}} key="{{ lookup('file', 'id_rsa.pub') }}"
  sudo: yes

When I run the playbook, I get this message:

PLAY [Master Node] ************************************************************

GATHERING FACTS *************************************************************** ok: [127.0.0.1]

TASK: [Adding user] ************************************************** changed: [127.0.0.1] => {"changed": true, "comment": "", "createhome": >true, "group": 1001, "groups": "root", "home": "/home/nikolas", "name": >"nikolas", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", >"state": "present", "system": false, "uid": 1001}

TASK: [Placing RSA key] ******************************************************* changed: [127.0.0.1] => {"changed": true, "key": "ssh-rsa >AAAAB3N....public_rsa_key", "key_options": null, >"keyfile": "/home/desmotes/.ssh/authorized_keys", "manage_dir": true, >"path": null, "state": "present", "unique": false, "user": "nikolas"}

PLAY RECAP ******************************************************************** 127.0.0.1 : ok=4 changed=2 unreachable=0 >failed=0

"password": "NOT_LOGGING_PASSWORD" As a result, when i am trying to logged in as nikolas in the VM to get authentication error.

Do you know where is my mistake ?

Thank you

1

1 Answers

1
votes

I think you need to modified your user creation task like this:

- name: Adding user
  user: name={{username}} shell=/bin/bash groups=root append=yes password={{ pass | password_hash('sha512') }}
  sudo: yes

Hope that help you.