Copy SSK Keys using Ansible

Lately I have been working on rolling out Ansible across the Infrastructure.  One of the step is to set up SSH key-based authentication, which would allow to set ask_pass = false. In order to accomplish this I have used the Ansible module authorized_key module which allows to add SSH authorized keys for particular user accounts. Following is the playbook which I have written to complete this tasks.

- name: Copy SSH Authorized Key to remote host
  hosts: all
  vars:
    username: ENTER REMOTE USERNAME
  tasks:
  - name: Set Authorized Key for user "{{ username }}"
    authorized_key:
      user: "{{ username }}"
      key: "{{ lookup('file', '/home/USERNAME/.ssh/id_rsa.pub') }}"
      state: present

While executing the playbook I have used the -k to get the password for the remote user which is configured the ansible.cfg file.

 

Share

You must be logged in to post a comment.

Proudly powered by WordPress   Premium Style Theme by www.gopiplus.com