Skip to content

Commit

Permalink
Ensure SSH directory exists on molecule instances
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Dec 10, 2024
1 parent 1fd458b commit 1746f5f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions automation/molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,38 @@
ssh_client_package: "{{ 'openssh-client' if ansible_os_family == 'Debian' else 'openssh-clients' }}"
when: ansible_distribution != "MacOSX"

- name: Get system username
ansible.builtin.command: whoami
register: system_user
changed_when: false
delegate_to: localhost
run_once: true

- name: Generate molecule SSH key on control node
ansible.builtin.user:
name: "{{ system_user.stdout }}"
name: "{{ ansible_facts.user | default('root') }}"
generate_ssh_key: true
ssh_key_bits: 2048
ssh_key_file: ~/.ssh/molecule_rsa
delegate_to: localhost
run_once: true
run_once: true # noqa run-once

- 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: ~/.ssh/molecule_rsa.pub
dest: /root/.ssh/authorized_keys
owner: root
group: root
dest: "{{ ansible_env.HOME }}/.ssh/authorized_keys"
owner: "{{ ansible_facts.user | default('root') }}"
group: "{{ ansible_facts.user | default('root') }}"
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: "~/.ssh/molecule_rsa"
ansible_user: "root"
ansible_user: "{{ ansible_facts.user | default('root') }}"

- name: Set variables for PostgreSQL Cluster deployment test
ansible.builtin.set_fact:
Expand Down

0 comments on commit 1746f5f

Please sign in to comment.