generated from the-liberated-edge/wikijs
i-1 Introduces an Ansible playbook for linux-container with SSH access
# Issue This PR implements the following [issue](the-liberated-edge/test-linux-containers#1). # Acceptance criteria - [x] A playbook for launching LXD Debian container with parameterized container name and OS version has been implemented. - [x] The newly launched Linux containers can be connected to and administered via SSH. - [x] The playbook has been part of an Ansible collection named theliberatededge.test_linux_containers. - [x] Setup and getting started technical documentation has been added to README.md. Co-authored-by: emo <esimeonov@gmail.com> Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
10
extensions/molecule/default/converge.yml
Normal file
10
extensions/molecule/default/converge.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
- name: imports and executes the playbook under test
|
||||
ansible.builtin.import_playbook: theliberatededge.test_linux_containers.launch_linux_container.yml
|
||||
vars:
|
||||
lte_debian_version: bookworm
|
||||
lte_container_name: '{{ molecule_yml.platforms[0].name }}'
|
||||
lte_container_root_pwd: '{{ lookup("ansible.builtin.env", "LTE_CONTAINER_ROOT_PWD") }}'
|
||||
18
extensions/molecule/default/destroy.yml
Normal file
18
extensions/molecule/default/destroy.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
- name: Create
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: find current container state
|
||||
ansible.builtin.command: lxc ls {{ item.name }}
|
||||
register: state
|
||||
changed_when: false
|
||||
with_items: '{{ molecule_yml.platforms }}'
|
||||
- name: stop and remove running containers
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
lxc stop {{ item.name }} && \
|
||||
lxc rm {{ item.name }}
|
||||
when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout
|
||||
with_items: '{{ molecule_yml.platforms }}'
|
||||
12
extensions/molecule/default/molecule.yml
Normal file
12
extensions/molecule/default/molecule.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
platforms:
|
||||
- name: ${LTE_CONTAINER_NAME}
|
||||
provisioner:
|
||||
name: ansible
|
||||
playbooks:
|
||||
create: destroy.yml
|
||||
destroy: destroy.yml
|
||||
verifier:
|
||||
name: ansible
|
||||
33
extensions/molecule/default/verify.yml
Normal file
33
extensions/molecule/default/verify.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
- name: Verify
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: find current container state
|
||||
ansible.builtin.command: lxc ls {{ item.name }}
|
||||
register: state
|
||||
with_items: '{{ molecule_yml.platforms }}'
|
||||
- name: verify launched container is running
|
||||
ansible.builtin.assert:
|
||||
that: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout
|
||||
- name: find container ip address
|
||||
ansible.builtin.command: lxc ls -c=4 -f=compact {{ item.name }}
|
||||
register: ipv4_raw
|
||||
with_items: '{{ molecule_yml.platforms }}'
|
||||
- name: set ipv4 address string as a fact
|
||||
ansible.builtin.set_fact:
|
||||
ipv4: '{{ ipv4_raw.results[0].stdout_lines[1] }}'
|
||||
- name: extract ipv4 address of the linux container
|
||||
ansible.builtin.set_fact:
|
||||
ipv4: "{{ ipv4 | regex_search('([0-9]+.[0-9]+.[0-9]+.[0-9]+)') }}"
|
||||
- name: load root password from environment variable
|
||||
ansible.builtin.set_fact:
|
||||
pwd: "{{ lookup('ansible.builtin.env', 'LTE_CONTAINER_ROOT_PWD') }}"
|
||||
- name: connect via ssh to linux container
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
sshpass -p{{ pwd }} ssh -o ConnectTimeout=1 root@{{ ipv4 }} exit;
|
||||
register: ssh
|
||||
- name: verify ssh connection to linux container
|
||||
ansible.builtin.assert:
|
||||
that: ssh.rc == 0
|
||||
Reference in New Issue
Block a user