Skip to content

Commit

Permalink
Update converge.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Dec 10, 2024
1 parent 6042704 commit 1dbbe34
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions automation/molecule/postgrespro/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,68 @@
gather_facts: true

tasks:
- name: Update apt cache
become: true
become_method: su
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
when: ansible_os_family == "Debian"

- name: Ensure SSH client package is installed
become: true
become_method: su
ansible.builtin.package:
name: "{{ ssh_client_package }}"
state: present
vars:
ssh_client_package: "{{ 'openssh-client' if ansible_os_family == 'Debian' else 'openssh-clients' }}"
when: ansible_distribution != "MacOSX"

- name: Get system username on control node
ansible.builtin.command: whoami
register: control_user
changed_when: false
delegate_to: localhost
run_once: true # noqa run-once

- name: Generate molecule SSH key on control node
ansible.builtin.user:
name: "{{ control_user.stdout }}"
generate_ssh_key: true
ssh_key_bits: 2048
ssh_key_file: /tmp/molecule_rsa
delegate_to: localhost
run_once: true # noqa run-once

- name: Get system username on molecule instances
ansible.builtin.command: whoami
register: instance_user
changed_when: false

- name: Ensure SSH directory exists on molecule instances
become: true
become_method: su
ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.ssh"
state: directory
mode: '0700'

- name: Copy public SSH key to molecule instances
become: true
become_method: su
ansible.builtin.copy:
src: /tmp/molecule_rsa.pub
dest: "{{ ansible_env.HOME }}/.ssh/authorized_keys"
owner: "{{ instance_user.stdout }}"
group: "{{ instance_user.stdout }}"
mode: '0600'

- name: Switch to SSH key-based authentication
ansible.builtin.set_fact:
ansible_ssh_common_args: "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
ansible_private_key_file: /tmp/molecule_rsa

- name: Set variables for molecule
ansible.builtin.set_fact:
firewall_enable_ipv6: false # Added to prevent test failures in CI.
Expand Down

0 comments on commit 1dbbe34

Please sign in to comment.