0

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   |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   |                    |   |        |                            |
|   +--------------------+   |        |                            |
|                            |        |                            |
+----------------------------+        +----------------------------+
Darthtrader
  • 238
  • 1
  • 8
  • Haven't you asked the same question yesterday? – techraf Jun 23 '17 at 01:25
  • 1
    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 Jun 23 '17 at 03:24

1 Answers1

3

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.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Given that cloud-init is only available on Ubuntu images from cloud-images.ubuntu.com, I'd like to know how you use it on other images from images.linuxcontainers.org. Thanks – Roberto Damian Alfonso Oct 03 '17 at 20:46