Ansible: User ssh access
(Redirected from User ssh access)
Jump to navigation
Jump to search
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:
- User Module doc: https://docs.ansible.com/ansible/latest/modules/user_module.html#user-module
- SSH authorized key module: https://docs.ansible.com/ansible/latest/modules/authorized_key_module.html#authorized-key-module
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]
with_items
https://docs.ansible.com/ansible/latest/plugins/lookup/items.html- Use loops in task (Ansible)
- Ansible: modules, plugins, Playbooks (examples)
ansible-playbook
,ansible-vault
,ansible-inventory
,ansible-config
, Ansible Tower, Ansible Galaxy (Roles) (ansible-galaxy
),ansible-cmdb
,gather facts
,ansible.cfg
,Ansible Molecule
, Ansible collections,register
,template
,--ask-pass
,--ask-become-pass
,remote_user:
,/etc/ansible/hosts
,ansible-doc
,ansible-lint
,.ansible/
,--forks
,--start-at-task
,changelog
,inventory
,Notify:
,ansible HOSTNAME -m ping
,gathering
,/usr/bin/ansible
,ansible -m ping
,ansible.builtin
,hosts: (Ansible)
,set fact:
,when:
,blockinfile:
,become method:
,include:
,git:
, AWX,ansible --help
, Tags, Ansible variables, versions
Template:CC License
Source: https://en.wikiversity.org/wiki/DevOps/Ansible/User_ssh_access
Advertising: