--- # Copyright 2015, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - name: Playbook for role testing hosts: localhost connection: local become: true vars: bridges: [] nspawn_networks: nspawn_address: bridge: "nspawn0" private_device: true enable_dhcp: true dhcp_range: 10.100.101.2,10.100.101.129 address: 10.100.101.1 netmask: 255.255.255.0 macvlan_mode: bridge pre_tasks: - name: Show host facts debug: var: hostvars - name: First ensure apt cache is always refreshed apt: update_cache: yes when: - ansible_pkg_mgr == 'apt' - name: Ensure root ssh key user: name: "{{ ansible_env.USER | default('root') }}" generate_ssh_key: "yes" ssh_key_bits: 2048 ssh_key_file: ".ssh/id_rsa" - name: Get root ssh key slurp: src: '~/.ssh/id_rsa.pub' register: _root_ssh_key - name: Prepare container ssh key fact set_fact: nspawn_container_ssh_key: "{{ _root_ssh_key['content'] | b64decode }}" roles: - role: "nspawn_hosts" nspawn_container_base_name: "test-container" nspawn_container_cache_files: - src: files/container-file-copy-test.txt dest: /tmp/file-copied-from-deployment-host.txt post_tasks: - name: Check for nspawn bridge stat: path: /sys/class/net/nspawn0/upper_mv-nspawn0 changed_when: false register: nspawn_interface_file - name: Check role functions assert: that: - "nspawn_interface_file.stat.exists" - name: Check dnsmasq is running command: systemctl status dnsmasq-mv-nspawn0.service changed_when: false tags: - skip_ansible_lint - name: Check for machines mount command: "systemctl status var-lib-machines.mount" changed_when: false tags: - skip_ansible_lint - name: Check dnsmasq is running command: systemctl status dnsmasq-mv-nspawn0.service changed_when: false tags: - skip_ansible_lint - name: Check for valid BTRFS file system command: "btrfs filesystem show /var/lib/machines" changed_when: false - name: Check for base container command: "machinectl show-image test-container" changed_when: false - name: Ensure images can be cloned command: "machinectl clone test-container test1" changed_when: false - name: Ensure images can be removed command: "machinectl remove test1" changed_when: false - name: Ensure images can be marked read-only command: "machinectl read-only test-container yes" changed_when: false - name: Ensure a read-only image is read-only file: path: /var/lib/machines/test-container/test-file state: touch failed_when: - read_only_test is success register: read_only_test - name: Remove base image command: "machinectl remove test-container" changed_when: false