|
| 1 | +--- |
| 2 | +# Copyright (c) 2024 Oracle and/or its affiliates. |
| 3 | +# This software is made available to you under the terms of the Universal Permissive License (UPL), Version 1.0. |
| 4 | +# The Universal Permissive License (UPL), Version 1.0 (see COPYING or https://oss.oracle.com/licenses/upl) |
| 5 | +# See LICENSE.TXT for details. |
| 6 | + |
| 7 | +- name: Generate ssh keypair for user |
| 8 | + community.crypto.openssh_keypair: |
| 9 | + path: ~/.ssh/id_rsa |
| 10 | + size: 2048 |
| 11 | + comment: ocne ssh keypair |
| 12 | + become: true |
| 13 | + become_user: "{{ username }}" |
| 14 | + |
| 15 | +- name: Fetch public key file from server |
| 16 | + ansible.builtin.fetch: |
| 17 | + src: "~/.ssh/id_rsa.pub" |
| 18 | + dest: "buffer/{{ inventory_hostname }}-id_rsa.pub" |
| 19 | + flat: true |
| 20 | + become: true |
| 21 | + become_user: "{{ username }}" |
| 22 | + |
| 23 | +- name: Copy public key to each destination |
| 24 | + ansible.posix.authorized_key: |
| 25 | + user: "{{ username }}" |
| 26 | + state: present |
| 27 | + key: "{{ lookup('file', 'buffer/{{ item }}-id_rsa.pub') }}" |
| 28 | + loop: "{{ groups['all'] | flatten(levels=1) }}" |
| 29 | + become: true |
| 30 | + |
| 31 | +- name: Print hostvars for groups |
| 32 | + ansible.builtin.debug: |
| 33 | + msg: "{{ hostvars[item] }}" |
| 34 | + loop: "{{ groups['all'] | flatten(levels=1) }}" |
| 35 | + when: debug_enabled |
| 36 | + |
| 37 | +- name: Print vnc subnet_domain_name |
| 38 | + ansible.builtin.debug: |
| 39 | + var: my_subnet_domain_name |
| 40 | + when: debug_enabled |
| 41 | + |
| 42 | +- name: Accept new ssh fingerprints |
| 43 | + ansible.builtin.shell: | |
| 44 | + ssh-keyscan -t ecdsa-sha2-nistp256 \ |
| 45 | + {{ hostvars[item].ansible_hostname }},\ |
| 46 | + {{ hostvars[item].ansible_default_ipv4.address }},\ |
| 47 | + {{ hostvars[item].ansible_hostname + '.' + my_subnet_domain_name }} >> ~/.ssh/known_hosts |
| 48 | + with_items: |
| 49 | + - "{{ groups['all'] }}" |
| 50 | + become: true |
| 51 | + become_user: "{{ username }}" |
| 52 | + register: result |
| 53 | + changed_when: result.rc == 0 |
0 commit comments