0

I have created a ansible code to create users and add respective ssh keys which is working successfully. But when trying to server access, it is asking for password.

Server is  127.0.0.1 or localhost

Ansible Script

tasks:
    - include_vars: users.yml
    - name: Create user
      user:
        name: "{{item.username}}"
      with_items: "{{ users }}"

    - name: Adding SSH key
      authorized_key:
        user: "{{ item.username }}"
        key: "{{ lookup ('file', 'keys/'+ item.username + '.key.pub') }}"
      with_items: "{{ users }}"

I am trying to connect through three ways :

1. ssh user@localhost - Asking for password
2. ssh -vvv user@localhost - Asking for password
3. ssh-copy-id user@localhost - Asking for password

If I go to ssh config file at set ask password flag to no than running anisble script next is giving permission issue which is valid case as that time public key for user will not be configured.

The solution which I am looking is once ssh key is set for user through ansible script, he must be able to login without password using ssh key.

NOTE :- The server is localhost/127.0.01 not any remote server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.