Enable ssh after creating LXC with Ansible

janvv

Member
Jun 21, 2020
52
5
13
64
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?
 

Denny

Active Member
Jul 28, 2016
86
20
28
58
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

Denny

Active Member
Jul 28, 2016
86
20
28
58
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.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!