Ansible: User ssh access

From wikieduonline
Revision as of 12:26, 26 December 2019 by Welcome (talk | contribs) (Created page with "Solution: touch create_user_with_public_key_access.yml If you are using this playbook for the first time and ssh key authentication is not configured modify first line to:...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Solution:

touch create_user_with_public_key_access.yml

If you are using this playbook for the first time and ssh key authentication is not configured modify first line to: #!/usr/bin/env ansible-playbook --ask-pass


#!/usr/bin/env ansible-playbook

- hosts: YOUR_HOST_GROUP
  vars:
    USERNAME: YOUR_USERNAME

  tasks:
  - name: Create user  
    user:
      name: "{{ USERNAME }}"
      #comment: Add you comment here

  - name: Set authorized key defining and key options for user XXXXXX
    authorized_key:
      user: "{{ USERNAME }}"
      state: present
      key: "{{ lookup('file', '/tmp/id_ed25519.pub') }}"           # Path to users public key

Execute: ansible-playbook create_user_with_public_key_access.yml References:


You can also loop over Subelements, check https://docs.ansible.com/ansible/2.4/playbooks_loops.html#looping-over-subelements.


See also

Advertising: