# Proxmox pct connetion

**URL:** <https://forum.ansible.com/t/proxmox-pct-connetion/5994>\
**Category:** Get Help\
**Tags:** proxmox, dev, plugin\
**Created:** [May 25, 2024, 1:25pm UTC](https://forum.ansible.com/t/proxmox-pct-connetion/5994 "2024-05-25T13:25:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mietzen](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mietzen/32/3025_2.png) [@mietzen](https://forum.ansible.com/u/mietzen)\
**Post date:** [May 25, 2024, 1:25pm UTC](https://forum.ansible.com/t/proxmox-pct-connetion/5994/1 "2024-05-25T13:25:21Z")

</div>

Hi,

wanted to build a connection plugin similar to `lxc`. It should directly connect into the container on a proxmox host that is not reachable via ssh.

This is my code so far (NOT finished):  
[https://github.com/mietzen/community.general/blob/add-pct-connection/plugins/connection/pct.py](https://github.com/mietzen/community.general/blob/add-pct-connection/plugins/connection/pct.py)

But I hit some road bumps and I’m not sure if what I want to archive is possible.

## What I wanted:

Call a playbook from my Laptop execute it on the proxmox host inside the container using `pct exec`.

## What I got:

My code is trying to run on my Laptop and fails because it can’t find `pct`.

I read that we can only use one connection per host, so is what I wanted to archive impossible? Or must I warp the ptc connection inside a ssh tunnel?

So something like:

```python
remote_cmd = [
    self._pct_cmd,
    "exec",
    self._vmid(),
    "--",
    self.get_option("executable"), "-c", cmd])

ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username=user, pkey=k)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(' '.join(remote_cmd))

```

---

<div class="post-metadata">

**Author:** ![mietzen](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mietzen/32/3025_2.png) [@mietzen](https://forum.ansible.com/u/mietzen)\
**Post date:** [May 26, 2024, 2:34pm UTC](https://forum.ansible.com/t/proxmox-pct-connetion/5994/2 "2024-05-26T14:34:26Z")

</div>

I figured it out, it works:

> <https://github.com/ansible-collections/community.general/pull/8424>
>
> \##### SUMMARY
> This connection plugin uses ssh (\`paramiko\`) to connect to a prox…mox host and then calls \`pct\` to connect into the LXC Proxmox container. 
> 
> I mainly inherited from \`ssh\_paramiko\` and overwrote the main methods. 
> 
> \##### Why is this useful? 
> With the new SDN functionality in proxmox we might want to create container that are not reachable via ssh. With this plugin we can use ansible within the container without any network access to the container.
> 
> \##### ISSUE TYPE
> \- New Module/Plugin Pull Request
> 
> \##### COMPONENT NAME
> pct\_remote
> 
> \##### ADDITIONAL INFORMATION
> \`pct\` can only be executed as \`root\` this is why I put \`/usr/bin/sudo\` in front of it, I think this is not very clean. Is there a way to obtain the binary path from \`become\_method\`? Or is it possible to set \`become: true\` as default?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 25, 2024, 2:34pm UTC](https://forum.ansible.com/t/proxmox-pct-connetion/5994/3 "2024-06-25T14:34:33Z")

</div>

Closed on June 25, 2024, 2:34pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
