forked from juju4/ansible-bind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml.lxd
99 lines (92 loc) · 6.88 KB
/
.travis.yml.lxd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
dist: trusty
sudo: required
rvm:
- 2.4
env:
## those images need pre-configuration before being usable (openssh...)
# - distribution: centos
# version: 6
# - distribution: centos
# version: 7
- distribution: ubuntu
version: 16.04
- distribution: ubuntu
version: 14.04
# - distribution: ubuntu
# version: 12.04
# - distribution: alpine
# version: 3.4
# - distribution: debian
# version: jessie
before_install:
- env
- pwd
- find -ls
## use appropriate role path and not github name
- "[ -f get-dependencies.sh ] && sh -x get-dependencies.sh"
## No Xenial, https://github.com/travis-ci/travis-ci/issues/5821
# - sudo apt install lxd
- echo "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/trusty-backports.list
- sudo apt-get update -qq
- sudo apt -t trusty-backports -y install lxd acl -q
## change of group implies logout+login to apply... can't do with travis = run as root (sic) = use 'newgrp lxd' ?
## https://github.com/travis-ci/travis-ci/issues/1839 or chain: sudo -E su $USER -c "..."
- sudo usermod -G lxd travis
# - newgrp lxd
# Pull container
- sudo -E su $USER -c "lxc remote list"
- sudo -E su $USER -c "lxc image list"
## pre-download base images
- 'sudo -E su $USER -c "[ ${distribution} == ubuntu ] || lxc image copy images:${distribution}/${version}/amd64 local: --alias=${distribution}-${version}"'
- 'sudo -E su $USER -c "[ ${distribution} == ubuntu ] && lxc image copy ubuntu:${version} local: --alias=${distribution}-${version}" || true'
## configure lxd-bridge
- sudo perl -pi -e 's@^LXD_IPV4_ADDR=""@LXD_IPV4_ADDR="10.252.116.1"@;s@^LXD_IPV4_NETMASK=""@LXD_IPV4_NETMASK="255.255.255.0"@;s@^LXD_IPV4_NETWORK=""@LXD_IPV4_NETWORK="10.252.116.1/24"@;s@^LXD_IPV4_DHCP_RANGE=""@LXD_IPV4_DHCP_RANGE="10.252.116.2,10.252.116.254"@;s@^LXD_IPV4_DHCP_MAX=""@LXD_IPV4_DHCP_MAX="252"@;s@LXD_IPV6_PROXY="true"@LXD_IPV6_PROXY="false"@' /etc/default/lxd-bridge
# - cat /etc/default/lxd-bridge
# - service --status-all
- sudo service lxd restart
## ssh key for lxd_cli ?
- ls ~/.ssh
- ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -P ""
## sudo/su get us a non-usual PATH ...
- sudo -E su $USER -c "lxc launch ${distribution}-${version} run-${distribution}-${version//./}"
# - sudo -E su $USER -c "lxc start run-${distribution}-${version//./}"
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- env"
- '[ "X${distribution}" != "Xalpine" ] && sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- dhclient eth0" || true'
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- ping -c 1 8.8.8.8"
- '[ "X${distribution}" == "Xubuntu" ] && sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- apt-get update" || true'
- '[ "X${distribution}" == "Xubuntu" ] && sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- apt-get -y install python python-apt aptitude python-pip libssl-dev python-dev libffi-dev" || true'
- '[ "X${distribution}" == "Xcentos" -a "X${version}" == "X6" ] && sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm" || true'
- '[ "X${distribution}" == "Xcentos" -a "X${version}" == "X7" ] && sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm" || true'
- '[ "X${distribution}" == "Xcentos" ] && sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- yum update" || true'
- '[ "X${distribution}" == "Xcentos" ] && sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- yum -y install python python-pip openssl-devel python-devel libffi-devel \"@Development tools\"" || true'
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- pip install ansible"
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- ansible --version"
- "echo localhost > inventory"
## enable ansible profiling (https://github.com/jlafon/ansible-profile)
# - "printf '[defaults]\ncallback_whitelist = profile_tasks' > ansible.cfg"
# - sudo -E su $USER -c "lxc file push inventory ansible.cfg run-${distribution}-${version//./}/root/"
- sudo -E su $USER -c "lxc file push inventory run-${distribution}-${version//./}/root/"
## these lines are necessary so lxc mount is read-write, https://github.com/lxc/lxd/issues/1879
- chmod -R go+w $PWD
## OR
- sudo -E su $USER -c "lxc config show run-${distribution}-${version//./}"
## FIXME! awk extraction is working in shell but not in travis... relying on global chmod as test ephemeral environment. DON'T USE IN PRODUCTION!
- sudo -E su $USER -c "lxc config show run-${distribution}-${version//./} | awk -F'[\":,]' '/Hostid/ { print $13 }'"
- CUID=`sudo -E su $USER -c "lxc config show run-${distribution}-${version//./} | awk -F'[\":,]' '/Hostid/ { print $13 }'"`
- "echo setfacl -Rm user:$CUID:rwx ${PWD%/*}"
- "setfacl -Rm user:$CUID:rwx ${PWD%/*}"
- sudo -E su $USER -c "lxc config device add run-${distribution}-${version//./} sharedroles disk path=/etc/ansible/roles source=${PWD%/*}"
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- mount"
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- pwd"
script:
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- ansible-playbook -i inventory --syntax-check /etc/ansible/roles/juju4.bind/test/integration/default/default.yml"
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- ansible-playbook -i inventory --connection=local --sudo -vvvv /etc/ansible/roles/juju4.bind/test/integration/default/default.yml"
## FIXME! Travis request: Build config file had a parse error: "mapping values are not allowed in this context at line 72 column 321".
# - sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- ansible-playbook -i inventory /etc/ansible/roles/juju4.bind/test/integration/default/default.yml --connection=local --sudo | tee /tmp/idempotency.log | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && cat /tmp/idempotency.log && exit 1)"
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- ansible-playbook -i inventory --connection=local --sudo /etc/ansible/roles/juju4.bind/test/integration/default/default.yml" > /tmp/idempotency.log
- "grep -q 'changed=0.*failed=0' /tmp/idempotency.log && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && cat /tmp/idempotency.log && exit 1)"
- sudo -E su $USER -c "lxc exec run-${distribution}-${version//./} -- time sh -x /etc/ansible/roles/juju4.bind/test/integration/default/serverspec/run-local-tests.sh"
- sudo -E su $USER -c "lxc stop run-${distribution}-${version//./} --force"
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/