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