Skip to content

Commit 54d0484

Browse files
authored
Merge pull request #26 from bgraef/main
add pwdless-ssh to ol and ingress for haproxy
2 parents 854e775 + 5bdd8b7 commit 54d0484

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ vm_root_pass:
3838
cleanup_tmp: no
3939

4040
update_all: false
41-
use_podman: false
41+
passwordless_ssh: false
42+
use_podman: false
43+
use_haproxy: 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

ol/templates/ingress_security_rules.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ instance_ingress_security_rules:
1212
destination_port_range:
1313
max: 22
1414
min: 22
15+
{% if use_haproxy %}
16+
- source: "10.0.0.0/24"
17+
protocol: 6
18+
tcp_options:
19+
destination_port_range:
20+
max: 8080
21+
min: 8080
22+
{% endif %}

0 commit comments

Comments
 (0)