0
votes

How to launch and LXD container on another node and exchange ssh keys with the container? That is, how to give Ansible direct access to the LXD container using SSH?

I am aware of the authorized_key module however this would only exchange keys between the host and Ansible and not Ansible and the LXD container.

Please see the below diagram which describes the machine layout:

+----------------------------+        +----------------------------+
|                            |        |                            |
|     Baremetal Machine  <------------------+ Ansible Machine      |
|              +             |        |                            |
|              |             |        |                            |
|              |             |        |                            |
|              |             |        |                            |
|   +--------------------+   |        |                            |
|   |          |         |   |        |                            |
|   |          v         |   |        |                            |
|   |    LXD Container   |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   +--------------------+   |        |                            |
|                            |        |                            |
+----------------------------+        +----------------------------+
1
Haven't you asked the same question yesterday?techraf
The question yesterday had negligible views so I reworded it to make it clearer. Although it may be difficult to perceive for a long time Ansible user, there is a rather large knowledge gap needed to go from bash scripts to Ansible Playbooks. With the continued move to containerization I am certain that this question will help many people.Darthtrader

1 Answers

3
votes

Start containers from images that support some sort of provisioning system.
Most common is cloud-init – it's already inside many official cloud images.

When you create such a container, just add required configuration settings via user.user-data config option and it will be automatically applied when container started.

lxd_container module support config parameter to set container configuration options.

You can find useful cloud config examples here.