Enable ssh after creating LXC with Ansible

janvv

Active Member
Jun 21, 2020
64
12
28
67
52.24154182722349, 5.117853866801705
I am creating Ansible playbooks to try to automate everything as much as possible.
I have my made my own proxmox_lxc role that works perfectly, using the CT templates that are available out of the box.

The thing is: after starting the container I cannot ssh into it from the outside world, which makes it unable to start another playbook to set up what I want to have in the container.
The required steps are documented in this forum post: https://forum.proxmox.com/threads/cannot-ssh-to-new-container.38114/
It works perfect when I do this manually, but I want to have it done through automation. I feel like having a kind of chicken egg problem.

The only solution I can think of is making my own container template having ssh enabled. But that would be bit of a bummer, because I want to avoid manual intervention as much as possible.

Any suggestions?
 
You can push the desired ssh keys into the running container from the proxmox host with something like
Code:
pct push <vmid> authorized_keys /root/.ssh/authorized_keys
That would let you in turn ssh in and start customizing via ansible.
 
  • Like
Reactions: ProxmoxEasy
Eventually you will probably run across the use case of needing the same feature for VM's. This is predicated on the kvm agent being installed.
Code:
qm guest exec <vmid>  -- "wget" "http://gitlab.myrepo.com/root/my-test-item/-/raw/master/authorized_keys" "-O" "/root/.ssh/authorized_keys"

You should also investigate the cloud.init functionality as well.