-
Notifications
You must be signed in to change notification settings - Fork 2
add lxd virtualization #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a27aa40
fa657d0
e36294c
8a4cf4c
e00c567
9209aa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --- | ||
| - name: Manage LXD containers and set Pulumi ESC | ||
| hosts: localhost | ||
| gather_facts: false | ||
| connection: local | ||
| become: true | ||
| vars: | ||
| molecule_inventory: | ||
| molecule: | ||
| hosts: {} | ||
| molecule_yml: | ||
| platforms: | ||
| - name: instance | ||
| image_fingerprint: "noble" | ||
| architecture: x86_64 | ||
| user: ansible | ||
|
|
||
| tasks: | ||
| - name: Check if LXD is installed | ||
| ansible.builtin.command: lxd --version | ||
| register: lxd_check | ||
| ignore_errors: true | ||
|
|
||
| - name: Fail if LXD is not installed | ||
| ansible.builtin.fail: | ||
| msg: | | ||
| LXD is not installed on this system. | ||
| Please install LXD before running this playbook. | ||
| For installation instructions, visit: https://linuxcontainers.org/lxd/getting-started-cli/ | ||
| when: lxd_check.rc != 0 | ||
|
|
||
| - name: Check if LXD is initialized | ||
| ansible.builtin.command: lxd waitready --timeout=5 | ||
| register: lxd_initialized | ||
| ignore_errors: true | ||
|
|
||
| - name: Fail if LXD is not initialized | ||
| ansible.builtin.fail: | ||
| msg: "LXD is not initialized or not ready. Please run 'sudo lxd init' manually." | ||
| when: lxd_initialized.rc != 0 | ||
|
|
||
| - name: Get ESC from Pulumi | ||
| ansible.builtin.command: esc open deeep-network/dev/services --format dotenv | ||
| changed_when: false | ||
| register: pulumi_esc | ||
|
|
||
| - name: Ensure cloud-init directory exists | ||
| ansible.builtin.file: | ||
| path: /etc/cloud | ||
| state: directory | ||
|
|
||
| - name: Write Pulumi ESC to cloud-init file | ||
| ansible.builtin.blockinfile: | ||
| path: /etc/cloud/cloud.cfg.d/01-pulumi-esc.cfg | ||
| block: | | ||
| # Pulumi ESC Configuration | ||
| {{ pulumi_esc.stdout }} | ||
|
|
||
| - name: Check if LXD container exists | ||
| ansible.builtin.command: lxc list "{{ platform['name'] }}" --format=json | ||
| register: lxd_container_info | ||
| ignore_errors: true | ||
| loop: "{{ molecule_yml['platforms'] }}" | ||
| loop_control: | ||
| loop_var: platform | ||
|
|
||
| - name: Debug container existence | ||
| ansible.builtin.debug: | ||
| var: lxd_container_info | ||
|
|
||
| - name: Create LXD containers if not exists using lxc launch | ||
| ansible.builtin.command: > | ||
| lxc launch ubuntu:{{ platform['image_fingerprint'] }} {{ platform['name'] }} | ||
| args: | ||
| creates: /var/lib/lxd/lxd.db | ||
| when: lxd_container_info.results[0].stdout == '[]' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current code assumes the first result from Spotted by Graphite Reviewer
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be fixed at next phase |
||
| loop: "{{ molecule_yml['platforms'] }}" | ||
| loop_control: | ||
| loop_var: platform | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| - name: Destroy LXD containers using command module | ||
| hosts: all | ||
| gather_facts: false | ||
| become: true | ||
| vars: | ||
| molecule_yml: | ||
| platforms: | ||
| - name: instance | ||
| user: ansible | ||
|
|
||
| tasks: | ||
| - name: Check if LXD container exists | ||
| ansible.builtin.command: lxc list "{{ platform['name'] }}" --format=json | ||
| register: lxd_container_info | ||
| ignore_errors: true | ||
| loop: "{{ molecule_yml['platforms'] }}" | ||
| loop_control: | ||
| loop_var: platform | ||
|
|
||
| - name: Debug container existence | ||
| ansible.builtin.debug: | ||
| var: lxd_container_info | ||
|
|
||
| - name: Destroy LXD containers if exists using lxc delete | ||
| ansible.builtin.command: > | ||
| lxc delete {{ platform['name'] }} --force | ||
| when: lxd_container_info.results[0].stdout != '[]' | ||
| loop: "{{ molecule_yml['platforms'] }}" | ||
| loop_control: | ||
| loop_var: platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add the following to ensure Pulumi ESC gets set in the
cloud-initfile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added without testing