Skip to content

Commit

Permalink
Override become_method
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Dec 10, 2024
1 parent d2c927c commit 7143396
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 265 deletions.
4 changes: 0 additions & 4 deletions .config/molecule/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ provisioner:
group_vars: ../../group_vars/
playbooks:
prepare: prepare.yml
connection_options:
ansible_ssh_common_args: "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
ansible_private_key_file: "/tmp/molecule_rsa"
ansible_user: "root"

scenario:
create_sequence:
Expand Down
88 changes: 1 addition & 87 deletions automation/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,98 +1,12 @@
---
- name: Prepare control node
hosts: localhost
gather_facts: true

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

- name: Ensure SSH client package is installed on control node
become: true
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

- 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

- name: Prepare molecule instances
hosts: all
gather_facts: true

tasks:
- name: Update apt cache on molecule instances
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 on molecule instances
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 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: Reset SSH connection to apply new credentials
ansible.builtin.meta: reset_connection

- name: Converge
hosts: all
gather_facts: true

tasks:
- name: Set variables for PostgreSQL Cluster deployment test
ansible.builtin.set_fact:
ansible_become_method: su # Override become_method
firewall_enabled_at_boot: false
firewall_enable_ipv6: false # Added to prevent test failures in CI.
swap_file_create: false # Added to prevent test failures in CI.
Expand Down
88 changes: 1 addition & 87 deletions automation/molecule/pg_upgrade/converge.yml
Original file line number Diff line number Diff line change
@@ -1,98 +1,12 @@
---
- name: Prepare control node
hosts: localhost
gather_facts: true

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

- name: Ensure SSH client package is installed on control node
become: true
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

- 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

- name: Prepare molecule instances
hosts: all
gather_facts: true

tasks:
- name: Update apt cache on molecule instances
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 on molecule instances
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 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: Reset SSH connection to apply new credentials
ansible.builtin.meta: reset_connection

- name: Converge
hosts: all
gather_facts: true

tasks:
- name: Set variables for Patroni cluster deployment test
ansible.builtin.set_fact:
ansible_become_method: su # Override become_method
firewall_enabled_at_boot: false
firewall_enable_ipv6: false # Added to prevent test failures in CI.
swap_file_create: false # Added to prevent test failures in CI.
Expand Down
88 changes: 1 addition & 87 deletions automation/molecule/postgrespro/converge.yml
Original file line number Diff line number Diff line change
@@ -1,98 +1,12 @@
---
- name: Prepare control node
hosts: localhost
gather_facts: true

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

- name: Ensure SSH client package is installed on control node
become: true
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

- 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

- name: Prepare molecule instances
hosts: all
gather_facts: true

tasks:
- name: Update apt cache on molecule instances
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 on molecule instances
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 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: Reset SSH connection to apply new credentials
ansible.builtin.meta: reset_connection

- name: Converge
hosts: all
gather_facts: true

tasks:
- name: Set variables for molecule
ansible.builtin.set_fact:
ansible_become_method: su # Override become_method
firewall_enable_ipv6: false # Added to prevent test failures in CI.
swap_file_create: false # Added to prevent test failures in CI.
sysctl_set: false # Added to prevent test failures in CI.
Expand Down

0 comments on commit 7143396

Please sign in to comment.