mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
pkgng: add basic integration tests
Test installing a package Test installing a package into a jail
This commit is contained in:
parent
5aff694dc4
commit
bfdaed0ce5
3 changed files with 212 additions and 0 deletions
5
tests/integration/targets/pkgng/aliases
Normal file
5
tests/integration/targets/pkgng/aliases
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
shippable/posix/group1
|
||||||
|
needs/root
|
||||||
|
skip/docker
|
||||||
|
skip/osx
|
||||||
|
skip/rhel
|
115
tests/integration/targets/pkgng/tasks/main.yml
Normal file
115
tests/integration/targets/pkgng/tasks/main.yml
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
---
|
||||||
|
- name: Test on FreeBSD VMs
|
||||||
|
when:
|
||||||
|
- ansible_facts.virtualization_type != 'docker'
|
||||||
|
- ansible_facts.distribution == 'FreeBSD'
|
||||||
|
block:
|
||||||
|
##
|
||||||
|
## pkgng - example - install single package
|
||||||
|
##
|
||||||
|
- name: Verify bash binary is not present
|
||||||
|
stat:
|
||||||
|
path: /usr/local/bin/bash
|
||||||
|
get_attributes: no
|
||||||
|
get_checksum: no
|
||||||
|
get_mime: no
|
||||||
|
register: pkgng_example1_stat_before
|
||||||
|
|
||||||
|
- name: Install bash
|
||||||
|
pkgng:
|
||||||
|
name: bash
|
||||||
|
register: pkgng_example1
|
||||||
|
|
||||||
|
- name: Remove bash (checkmode)
|
||||||
|
pkgng:
|
||||||
|
name: bash
|
||||||
|
state: absent
|
||||||
|
check_mode: yes
|
||||||
|
register: pkgng_example1_checkmode
|
||||||
|
|
||||||
|
- name: Install bash (idempotent)
|
||||||
|
pkgng:
|
||||||
|
name: bash
|
||||||
|
register: pkgng_example1_idempotent
|
||||||
|
|
||||||
|
- name: Verify bash binary is present
|
||||||
|
stat:
|
||||||
|
path: /usr/local/bin/bash
|
||||||
|
get_attributes: no
|
||||||
|
get_checksum: no
|
||||||
|
get_mime: no
|
||||||
|
register: pkgng_example1_stat_after
|
||||||
|
|
||||||
|
- name: Ensure pkgng installs package correctly
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not pkgng_example1_stat_before.stat.exists
|
||||||
|
- pkgng_example1.changed
|
||||||
|
- pkgng_example1_checkmode.changed
|
||||||
|
- not pkgng_example1_idempotent.changed
|
||||||
|
- pkgng_example1_stat_after.stat.exists
|
||||||
|
- pkgng_example1_stat_after.stat.executable
|
||||||
|
|
||||||
|
##
|
||||||
|
## pkgng - example - Install bash in jail
|
||||||
|
##
|
||||||
|
- name: Test within jail
|
||||||
|
#
|
||||||
|
# NOTE: FreeBSD 12.0 test runner receives a "connection reset by peer" after ~20% downloaded so we are
|
||||||
|
# only running this on 12.1 or higher
|
||||||
|
#
|
||||||
|
when: ansible_distribution_version is version('12.01', '>=')
|
||||||
|
block:
|
||||||
|
- name: Setup testjail
|
||||||
|
include: setup-testjail.yml
|
||||||
|
|
||||||
|
- name: Verify bash binary is not present
|
||||||
|
stat:
|
||||||
|
path: /usr/jails/testjail/usr/local/bin/bash
|
||||||
|
get_attributes: no
|
||||||
|
get_checksum: no
|
||||||
|
get_mime: no
|
||||||
|
register: pkgng_example2_stat_before
|
||||||
|
|
||||||
|
- name: Install bash
|
||||||
|
pkgng:
|
||||||
|
name: bash
|
||||||
|
jail: testjail
|
||||||
|
register: pkgng_example2
|
||||||
|
|
||||||
|
- name: Remove bash (checkmode)
|
||||||
|
pkgng:
|
||||||
|
name: bash
|
||||||
|
state: absent
|
||||||
|
jail: testjail
|
||||||
|
check_mode: yes
|
||||||
|
register: pkgng_example2_checkmode
|
||||||
|
|
||||||
|
- name: Install bash (idempotent)
|
||||||
|
pkgng:
|
||||||
|
name: bash
|
||||||
|
jail: testjail
|
||||||
|
register: pkgng_example2_idempotent
|
||||||
|
|
||||||
|
- name: Verify bash binary is present
|
||||||
|
stat:
|
||||||
|
path: /usr/jails/testjail/usr/local/bin/bash
|
||||||
|
get_attributes: no
|
||||||
|
get_checksum: no
|
||||||
|
get_mime: no
|
||||||
|
register: pkgng_example2_stat_after
|
||||||
|
|
||||||
|
- name: Ensure pkgng installs package correctly
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not pkgng_example2_stat_before.stat.exists
|
||||||
|
- pkgng_example2.changed
|
||||||
|
- pkgng_example2_checkmode.changed
|
||||||
|
- not pkgng_example2_idempotent.changed
|
||||||
|
- pkgng_example2_stat_after.stat.exists
|
||||||
|
- pkgng_example2_stat_after.stat.executable
|
||||||
|
always:
|
||||||
|
- name: Stop and remove testjail
|
||||||
|
failed_when: false
|
||||||
|
changed_when: false
|
||||||
|
command: "ezjail-admin delete -wf testjail"
|
92
tests/integration/targets/pkgng/tasks/setup-testjail.yml
Normal file
92
tests/integration/targets/pkgng/tasks/setup-testjail.yml
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
---
|
||||||
|
#
|
||||||
|
# Instructions for setting up a jail
|
||||||
|
# https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails-ezjail.html
|
||||||
|
#
|
||||||
|
- name: Setup cloned interfaces
|
||||||
|
lineinfile:
|
||||||
|
dest: /etc/rc.conf
|
||||||
|
regexp: ^cloned_interfaces=lo1
|
||||||
|
line: cloned_interfaces=lo1
|
||||||
|
|
||||||
|
- name: Activate cloned interfaces
|
||||||
|
command: "service netif cloneup"
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Add nat rule for cloned interfaces
|
||||||
|
copy:
|
||||||
|
dest: /etc/pf.conf
|
||||||
|
content: |
|
||||||
|
nat on {{ ansible_default_ipv4.interface }} from 127.0.1.0/24 -> {{ ansible_default_ipv4.interface }}:0
|
||||||
|
validate: "pfctl -nf %s"
|
||||||
|
|
||||||
|
- name: Start pf firewall
|
||||||
|
service:
|
||||||
|
name: pf
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
|
||||||
|
- name: Install ezjail
|
||||||
|
pkgng:
|
||||||
|
name: ezjail
|
||||||
|
|
||||||
|
- name: Configure ezjail to use http
|
||||||
|
when: ansible_distribution_version is version('11.01', '>')
|
||||||
|
lineinfile:
|
||||||
|
dest: /usr/local/etc/ezjail.conf
|
||||||
|
regexp: ^ezjail_ftphost
|
||||||
|
line: ezjail_ftphost=http://ftp.freebsd.org
|
||||||
|
|
||||||
|
- name: Configure ezjail to use archive for old freebsd releases
|
||||||
|
when: ansible_distribution_version is version('11.01', '<=')
|
||||||
|
lineinfile:
|
||||||
|
dest: /usr/local/etc/ezjail.conf
|
||||||
|
regexp: ^ezjail_ftphost
|
||||||
|
line: ezjail_ftphost=http://ftp-archive.freebsd.org
|
||||||
|
|
||||||
|
- name: Start ezjail
|
||||||
|
ignore_errors: yes
|
||||||
|
service:
|
||||||
|
name: ezjail
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
|
||||||
|
- name: Has ezjail
|
||||||
|
register: ezjail_base_jail
|
||||||
|
stat:
|
||||||
|
path: /usr/jails/basejail
|
||||||
|
|
||||||
|
- name: Setup ezjail base
|
||||||
|
when: not ezjail_base_jail.stat.exists
|
||||||
|
shell: "ezjail-admin install >> /tmp/ezjail.log"
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Has testjail
|
||||||
|
register: ezjail_test_jail
|
||||||
|
stat:
|
||||||
|
path: /usr/jails/testjail
|
||||||
|
|
||||||
|
- name: Create testjail
|
||||||
|
when: not ezjail_test_jail.stat.exists
|
||||||
|
shell: "ezjail-admin create testjail 'lo1|127.0.1.1' >> /tmp/ezjail.log"
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Configure testjail to use Cloudflare DNS
|
||||||
|
lineinfile:
|
||||||
|
dest: /usr/jails/testjail/etc/resolv.conf
|
||||||
|
regexp: "^nameserver[[:blank:]]+{{ item }}$"
|
||||||
|
line: "nameserver {{ item }}"
|
||||||
|
create: yes
|
||||||
|
loop:
|
||||||
|
- "1.1.1.1"
|
||||||
|
- "1.0.0.1"
|
||||||
|
|
||||||
|
- name: Is testjail running
|
||||||
|
shell: "jls | grep testjail"
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
register: is_testjail_up
|
||||||
|
|
||||||
|
- name: Start testjail
|
||||||
|
when: is_testjail_up.rc == 1
|
||||||
|
command: "ezjail-admin start testjail"
|
Loading…
Reference in a new issue