Skip to content

Commit 8eeb457

Browse files
author
William Graef
committed
add passwordless ssh option
1 parent 64fd8c7 commit 8eeb457

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

ol/create_instance.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@
295295
- name: Configure instance
296296
ansible.builtin.include_tasks: "host_setup.yml"
297297

298+
- name: Configure passwordless SSH
299+
ansible.builtin.include_tasks: "passwordless_setup.yml"
300+
when: passwordless_ssh
301+
298302
- name: Update all rpm packages
299303
ansible.builtin.import_playbook: update_all_rpms.yml
300304
when: update_all

ol/default_vars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ vm_root_pass:
3838
cleanup_tmp: no
3939

4040
update_all: false
41+
passwordless_ssh: false
4142
use_podman: false

ol/passwordless_setup.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)