Difference between revisions of "Ansible: User ssh access"

From wikieduonline
Jump to navigation Jump to search
(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:...")
 
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Solution:
 
  
touch create_user_with_public_key_access.yml
+
<code>touch create_user_with_public_key_access.yml</code>
  
 
If you are using this playbook for the first time and ssh key authentication is not configured modify first line to:
 
If you are using this playbook for the first time and ssh key authentication is not configured modify first line to:
Line 35: Line 34:
  
 
You can also loop over Subelements, check https://docs.ansible.com/ansible/2.4/playbooks_loops.html#looping-over-subelements.
 
You can also loop over Subelements, check https://docs.ansible.com/ansible/2.4/playbooks_loops.html#looping-over-subelements.
 +
 +
 +
== Related commands ==
 +
* <code>[[ssh-copy-id]]</code>
  
  
 
== See also ==
 
== See also ==
* <code>[[/with_items/]]</code> https://docs.ansible.com/ansible/latest/plugins/lookup/items.html
+
* <code>[[with_items]]</code> https://docs.ansible.com/ansible/latest/plugins/lookup/items.html
* [[DevOps/Ansible/Use loops in task]]
+
* [[Use loops in task (Ansible)]]
 
+
* {{Ansible}}
  
  
[[Category: Software development]]
+
[[Category:Ansible]]
 
[[Category:Server administration]]
 
[[Category:Server administration]]
  

Latest revision as of 05:56, 8 November 2020

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.


Related commands[edit]


See also[edit]


Template:CC License Source: https://en.wikiversity.org/wiki/DevOps/Ansible/User_ssh_access

Advertising: