---
- name: Create SSH keys for the user in question
  user: name={{ ssh_user }} generate_ssh_key=yes ssh_key_bits=2048
  register: sshkey

- name: Install key on remote hosts
  authorized_key: user={{ ssh_user }} key="{{ sshkey.ssh_public_key }}"
  delegate_to: "{{ item }}"
  with_items: play_hosts

- name: Setup known hosts file
  template: src=known_hosts.j2 dest=/etc/ssh/ssh_known_hosts mode=0644 owner=root group=root


---
- name: Create SSH keys for the user in question
  user: name={{ ssh_user }} generate_ssh_key=yes ssh_key_bits=2048

- name: Get the public key off the machine
  slurp:
    src: "~{{ ssh_user }}/.ssh/id_rsa.pub"
  register: sshkey

- name: Install key on remote hosts
  authorized_key: user={{ ssh_user }} key="{{ sshkey.content|b64decode }}"
  delegate_to: "{{ item }}"
  with_items: play_hosts

- name: Setup known hosts file
  template: src=known_hosts.j2 dest=/etc/ssh/ssh_known_hosts mode=0644 owner=root group=root


Fix a potential issue with SSH keys not being copied if a machine gets redeployed
Fix a potential issue with SSH keys not being copied if a machine gets redeployed
