unico
(Oleg)
February 28, 2022, 8:43am
1
I have my own local template LXD container witn name js-template
+-------------+--------------+--------+---------------------------------------------+--------------+-----------+----------+-------------------------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCHITECTURE | TYPE | SIZE | UPLOAD DATE |
+-------------+--------------+--------+---------------------------------------------+--------------+-----------+----------+-------------------------------+
| js-template | 9ccfebbd7807 | no | Ubuntu 20.04 LTS server (20220207) | x86_64 | CONTAINER | 428.65MB | Feb 25, 2022 at 1:04pm (UTC) |
+-------------+--------------+--------+---------------------------------------------+--------------+-----------+----------+-------------------------------+
| | 017d8572a250 | no | ubuntu 20.04 LTS amd64 (release) (20220207) | x86_64 | CONTAINER | 382.85MB | Feb 21, 2022 at 12:29pm (UTC) |
+-------------+--------------+--------+---------------------------------------------+--------------+-----------+----------+-------------------------------+
How can I use this template to create a new LXD container?
For example I will use this playbook.
- hosts: localhost
connection: local
tasks:
- name: Create a started container
lxd_container:
name: mycontainer
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: simplestreams
alias: ubuntu/xenial/amd64
profiles: ["default"]
wait_for_ipv4_addresses: true
timeout: 600
How can I modify the above to reach my goal, i.e. use the existing local image to deploy my new container?
tomp
(Thomas Parrott)
February 28, 2022, 2:37pm
2
lxc launch js-template c1
will use the js-template
image to create a container called c1
.
unico
(Oleg)
February 28, 2022, 3:42pm
3
Thanks for your reply
Yes, you are right, I used this is in shell
command to create container from js-template
lxc launch local:js-template js-alcanteradexuquer7 -p medium --target devel-lxd01
But I created playbook, and can not understend how I can use my container template js-template
to create new other container js-alcanteradexuquer7
. Could you please tell me, is this possible?
- name: Create LXD Container
become: True
lxd_container:
name: "{{ item.name }}"
state: started
ignore_volatile_options: true
source:
type: image
mode: pull
server: "{{ lxc_image_source }}"
protocol: simplestreams
alias: "{{ lxc_container_distro }}"
target: "{{ item.node }}"
profiles: "{{ lxc_profiles_medium }}"
wait_for_ipv4_addresses: true
timeout: 10
with_items: "{{ containers }}"
delegate_to: "{{ item.node }}"
My lxc remote list
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| NAME | URL | PROTOCOL | AUTH TYPE | PUBLIC | STATIC | GLOBAL |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| images | https://images.linuxcontainers.org | simplestreams | none | YES | NO | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| local (current) | unix:// | lxd | file access | NO | YES | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu | https://cloud-images.ubuntu.com/releases | simplestreams | none | YES | YES | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu-daily | https://cloud-images.ubuntu.com/daily | simplestreams | none | YES | YES | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
tomp
(Thomas Parrott)
March 1, 2022, 8:10am
4
When using lxc init <fingerprint> <instance_name>
the API request made is:
{
"architecture": "",
"config": {},
"devices": {},
"ephemeral": false,
"profiles": null,
"stateful": false,
"description": "",
"name": "<instance_name>",
"source": {
"type": "image",
"certificate": "",
"fingerprint": "<fingerprint>",
"allow_inconsistent": false
},
"instance_type": "",
"type": "container"
}
So I think the source
section there may be useful for your playbook.