adds launching debian container

This commit is contained in:
emo 2023-11-26 01:00:19 +01:00
parent 7d0b995efa
commit 4d7cab4425
6 changed files with 46 additions and 66 deletions

View File

@ -5,3 +5,5 @@
- name: imports and executes the playbook under test - name: imports and executes the playbook under test
ansible.builtin.import_playbook: ../../../launch_linux_container.yml ansible.builtin.import_playbook: ../../../launch_linux_container.yml
vars:
lte_container_name: "{{ molecule_yml.platforms[0].name }}"

View File

@ -1,36 +0,0 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
# no_log: "{{ molecule_no_log }}"
tasks:
# TODO: Developer must implement and populate 'server' variable
- name: Create instance config
when: server.changed | default(false) | bool # noqa no-handler
block:
- name: Populate instance config dict # noqa jinja
ansible.builtin.set_fact:
instance_conf_dict: {}
# instance': "{{ }}",
# address': "{{ }}",
# user': "{{ }}",
# port': "{{ }}",
# 'identity_file': "{{ }}", }
with_items: "{{ server.results }}"
register: instance_config_dict
- name: Convert instance config dict to a list
ansible.builtin.set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
- name: Dump instance config
ansible.builtin.copy:
content: |
# Molecule managed
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: 0600

View File

@ -1,24 +1,21 @@
--- ---
- name: Destroy - name: Create
hosts: localhost hosts: localhost
connection: local connection: local
gather_facts: false gather_facts: false
# no_log: "{{ molecule_no_log }}"
tasks: tasks:
# Developer must implement. - name: find current container state
ansible.builtin.command: "lxc ls {{ item.name }}"
register: container_state
changed_when: false
with_items: "{{ molecule_yml.platforms }}"
# Mandatory configuration for Molecule to function. - name: stop running containers
ansible.builtin.shell:
- name: Populate instance config cmd: |
ansible.builtin.set_fact: lxc stop {{ item.name }} && \
instance_conf: {} lxc rm {{ item.name }}
when:
- name: Dump instance config (container_state.results[0].rc == 0) and
ansible.builtin.copy: ("RUNNING" in container_state.results[0].stdout)
content: | with_items: "{{ molecule_yml.platforms }}"
# Molecule managed
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: 0600
when: server.changed | default(false) | bool # noqa no-handler

View File

@ -2,6 +2,11 @@
dependency: dependency:
name: galaxy name: galaxy
platforms: platforms:
- name: instance - name: ${LTE_CONTAINER_NAME}
provisioner:
name: ansible
playbooks:
create: destroy.yml
destroy: destroy.yml
verifier: verifier:
name: ansible name: ansible

View File

@ -3,10 +3,13 @@
hosts: localhost hosts: localhost
gather_facts: false gather_facts: false
tasks: tasks:
- name: stat file - name: find current container state
ansible.builtin.stat: ansible.builtin.command: "lxc ls {{ item.name }}"
path: ~/tst.log register: container_state
register: stat_result with_items: "{{ molecule_yml.platforms }}"
- name: verify file exists
- name: verify launched container is running
assert: assert:
that: stat_result.stat.exists that:
(container_state.results[0].rc == 0) and
("RUNNING" in container_state.results[0].stdout)

View File

@ -1,6 +1,15 @@
--- ---
- name: Task is running from within the role - name: find current container state
ansible.builtin.file: ansible.builtin.command: "lxc ls {{ lte_container_name }}"
path: ~/tst.log register: container_state
state: touch
changed_when: false changed_when: false
- name: launch debian bookworm linux container
ansible.builtin.shell:
cmd: |
lxc launch \
images:debian/bookworm/cloud \
{{ lte_container_name }}
when:
(container_state.rc == 1) or
("RUNNING" not in container_state.stdout)