mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
Proxmox remote pct connection (#8424)
* First Revision (squashed) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Second Revision (squashed) * implement data_in * Removed quot() There is no need for quoting, exec_command gets the command already quoted with shell from Ansible * Use shell from self._shell * Improved error handling * updated docs * Use Int for Container ID * Updated docs to include detailed description for non root usage * Fix ansible_user var in example * Fix become method We need to differentiate between become method used in Proxmox and the one inside the container. * Implement review findings - f-Strings - lower() when input - yaml indent - consistent quotes - use to_text() - Enhanced examples - Ansibullbot findings * remove ssh cache * Ensure we delete the tempfile * use octal mode * Use FileLock().lock_file * ansibullbot findings * refactor _connect() * Update plugins/connection/pct_remote.py Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * renamed plugin to proxmox_pct_remote * Use ansible.builtin.ping as example * added unit tests * fixed bugs in close() * catch invalid host key * test invalid host key * Added integration test * cleanup * setup test via ansible * Revised notes based on review feedback * Review findings Co-authored-by: Felix Fontein <felix@fontein.de> * gather_facts hint in example * Update tests/integration/targets/connection_proxmox_pct_remote/aliases Co-authored-by: Felix Fontein <felix@fontein.de> * Fix FreeBSD, deactivate macOS * Test and Fix: Hang on copy with empty content --------- Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
c823e37d00
commit
cee62a4069
11 changed files with 1578 additions and 0 deletions
|
@ -0,0 +1,12 @@
|
|||
# Copyright (c) 2025 Nils Stein (@mietzen) <github.nstein@mailbox.org>
|
||||
# Copyright (c) 2025 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/3
|
||||
destructive
|
||||
needs/root
|
||||
needs/target/connection
|
||||
skip/docker
|
||||
skip/alpine
|
||||
skip/macos
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
# Copyright (c) 2025 Nils Stein (@mietzen) <github.nstein@mailbox.org>
|
||||
# Copyright (c) 2025 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- hosts: localhost
|
||||
gather_facts: true
|
||||
serial: 1
|
||||
tasks:
|
||||
- name: Copy pct mock
|
||||
copy:
|
||||
src: files/pct
|
||||
dest: /usr/sbin/pct
|
||||
mode: '0755'
|
||||
- name: Install paramiko
|
||||
pip:
|
||||
name: "paramiko>=3.0.0"
|
33
tests/integration/targets/connection_proxmox_pct_remote/files/pct
Executable file
33
tests/integration/targets/connection_proxmox_pct_remote/files/pct
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2025 Nils Stein (@mietzen) <github.nstein@mailbox.org>
|
||||
# Copyright (c) 2025 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Shell script to mock proxmox pct behaviour
|
||||
|
||||
>&2 echo "[DEBUG] INPUT: $@"
|
||||
|
||||
pwd="$(pwd)"
|
||||
|
||||
# Get quoted parts and restore quotes
|
||||
declare -a cmd=()
|
||||
for arg in "$@"; do
|
||||
if [[ $arg =~ [[:space:]] ]]; then
|
||||
arg="'$arg'"
|
||||
fi
|
||||
cmd+=("$arg")
|
||||
done
|
||||
|
||||
cmd="${cmd[@]:3}"
|
||||
vmid="${@:2:1}"
|
||||
>&2 echo "[INFO] MOCKING: pct ${@:1:3} ${cmd}"
|
||||
tmp_dir="/tmp/ansible-remote/proxmox_pct_remote/integration_test/ct_${vmid}"
|
||||
mkdir -p "$tmp_dir"
|
||||
>&2 echo "[INFO] PWD: $tmp_dir"
|
||||
>&2 echo "[INFO] CMD: ${cmd}"
|
||||
cd "$tmp_dir"
|
||||
|
||||
eval "${cmd}"
|
||||
|
||||
cd "$pwd"
|
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- hosts: "{{ target_hosts }}"
|
||||
gather_facts: false
|
||||
serial: 1
|
||||
tasks:
|
||||
- name: create file without content
|
||||
copy:
|
||||
content: ""
|
||||
dest: "{{ remote_tmp }}/test_empty.txt"
|
||||
force: no
|
||||
mode: '0644'
|
||||
|
||||
- name: assert file without content exists
|
||||
stat:
|
||||
path: "{{ remote_tmp }}/test_empty.txt"
|
||||
register: empty_file_stat
|
||||
|
||||
- name: verify file without content exists
|
||||
assert:
|
||||
that:
|
||||
- empty_file_stat.stat.exists
|
||||
fail_msg: "The file {{ remote_tmp }}/test_empty.txt does not exist."
|
||||
|
||||
- name: verify file without content is empty
|
||||
assert:
|
||||
that:
|
||||
- empty_file_stat.stat.size == 0
|
||||
fail_msg: "The file {{ remote_tmp }}/test_empty.txt is not empty."
|
19
tests/integration/targets/connection_proxmox_pct_remote/runme.sh
Executable file
19
tests/integration/targets/connection_proxmox_pct_remote/runme.sh
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2025 Nils Stein (@mietzen) <github.nstein@mailbox.org>
|
||||
# Copyright (c) 2025 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set -eux
|
||||
|
||||
ANSIBLE_ROLES_PATH=../ \
|
||||
ansible-playbook dependencies.yml -v "$@"
|
||||
|
||||
./test.sh "$@"
|
||||
|
||||
ansible-playbook plugin-specific-tests.yml -i "./test_connection.inventory" \
|
||||
-e target_hosts="proxmox_pct_remote" \
|
||||
-e action_prefix= \
|
||||
-e local_tmp=/tmp/ansible-local \
|
||||
-e remote_tmp=/tmp/ansible-remote \
|
||||
"$@"
|
1
tests/integration/targets/connection_proxmox_pct_remote/test.sh
Symbolic link
1
tests/integration/targets/connection_proxmox_pct_remote/test.sh
Symbolic link
|
@ -0,0 +1 @@
|
|||
../connection_posix/test.sh
|
|
@ -0,0 +1,14 @@
|
|||
# Copyright (c) 2025 Nils Stein (@mietzen) <github.nstein@mailbox.org>
|
||||
# Copyright (c) 2025 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
[proxmox_pct_remote]
|
||||
proxmox_pct_remote-pipelining ansible_ssh_pipelining=true
|
||||
proxmox_pct_remote-no-pipelining ansible_ssh_pipelining=false
|
||||
[proxmox_pct_remote:vars]
|
||||
ansible_host=localhost
|
||||
ansible_user=root
|
||||
ansible_python_interpreter="{{ ansible_playbook_python }}"
|
||||
ansible_connection=community.general.proxmox_pct_remote
|
||||
proxmox_vmid=123
|
Loading…
Add table
Add a link
Reference in a new issue