ansible playbook ssh-keygen

74 views
Skip to first unread message

Tony Wong

unread,
Jun 28, 2022, 9:46:20 AM6/28/22
to Ansible Project
is there a module to run ssh-keygen on remote hosts?

any exmaples

Vladimir Botka

unread,
Jun 28, 2022, 11:04:48 AM6/28/22
to Tony Wong, ansible...@googlegroups.com
On Tue, 28 Jun 2022 06:46:20 -0700 (PDT)
Tony Wong <tdub...@gmail.com> wrote:

> is there a module to run ssh-keygen on remote hosts?

Yes. Module *user* is able to generate a SSH key. See
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html#parameter-generate_ssh_key


--
Vladimir Botka

Tony Wong

unread,
Jun 28, 2022, 11:54:51 AM6/28/22
to Vladimir Botka, ansible...@googlegroups.com
how about copying public key from another host to authorized_keys on the server? is there a module? or need ad hoc command

Brian Coca

unread,
Jun 28, 2022, 12:04:07 PM6/28/22
to Ansible Project, Vladimir Botka

Parth Patel

unread,
Jun 28, 2022, 12:10:26 PM6/28/22
to ansible...@googlegroups.com, Vladimir Botka
I guess user is trying copy authorized key from host A to host B if i didnt mis understood.

If so, use synchronize module with delegate_to parameter at task level

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7dwOvoMnMyqywt0g07gY6HKrA-r6cyLOYvX9eOYf%2BLzEQ%40mail.gmail.com.

Tony Wong

unread,
Jun 28, 2022, 12:27:08 PM6/28/22
to ansible...@googlegroups.com, Vladimir Botka
---
# tasks file for createuser
- include_vars:
   dir: vars

- name: create user sam
  ansible.builtin.user:
    name: '{{ username }}'
    group: '{{ groupname }}'
    shell: '{{ shell }}'
    generate_ssh_key: yes
    ssh_key_file: .ssh/id_rsa  
  become: true

does this do the same as

useradd sam
usermod -aG docker sam
su - sam
ssh-keygen -f ~/.ssh/id_rsa -P '' -q




You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/oxEKIhrfkt0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEMGyL%2BhHm6p5yrw91B5jX7NxrrXaMsN%2BQYTMrQrwJPT01cx-Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages