This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
.travis.yml
114 lines (96 loc) · 3.74 KB
/
.travis.yml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
language: python
python:
# - 2.7
# - 3.3
# - 3.4
# - 3.5
# - 3.6
- 3.7
- 3.8
services:
- docker
cache:
bundler:
directories:
- $HOME/.cache/pip
env:
global:
- JENKINS_HOME=/home/jenkins
- JENKINS_UID=3000
- DOCKER_GID=999
- secure: MD73NCVzctbVmi2QnQtwtH/ISXN2K0alsLbixoaXl7gr3XvTB4sYB0u+KKtPV46jbeAlQqTRObPfQouPrsLsiNDYcpuN0I5bKsn3TTs4ZHIkD0I2Q9Wh3qNM2fYf9mw3ZUhvXVTEod0W7jzkVGb6kitRCJj8rioKKzvE/YdVsG4=
matrix:
# - ANSIBLE_VERSION=latest
# - ANSIBLE_VERSION=2.7.14
- ANSIBLE_VERSION=2.9.4
sudo: required
#dist: trusty
dist: travis_lts
#dist: bionic
branches:
only:
- master
virtualenv:
system_site_packages: false
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl
- sudo apt-get install -qq curl
install:
# Install Ansible.
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible==$ANSIBLE_VERSION; fi
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible-lint; fi
- pip3 install molecule[docker,lint]==3.5.2
# Add ansible.cfg to pick up roles path.
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
# Prepare tests
# Add user jenkins to the image (travis is 2000)
- id -a
- getent passwd 3000 || true # 3000 not found we can use it for jenkins user
# - groupadd -g ${DOCKER_GID} docker && \
- sudo adduser --quiet --disabled-password --shell /bin/bash --uid ${JENKINS_UID} --gid ${DOCKER_GID} --home ${JENKINS_HOME} --gecos "Jenkins" jenkins
# Set password for the jenkins user (you may want to alter this).
# - sudo echo "jenkins:jenkins1234" | sudo chpasswd
# Update Ansible submodule.
- git pull && git submodule init && git submodule update && git submodule status
- git submodule foreach git checkout master
- ansible-galaxy install -r requirements.yml -p ./roles/ --ignore-errors
script:
# Check ansible version
- ansible --version
- yamllint . -c .yamllint
- ansible-lint . -c .ansible-lint
# - echo "${ANSIBLE_VAULT_PASS}" > vault.passwd
# Check the role/playbook's syntax.
- ansible-playbook -i ./hosts --syntax-check ./jenkins-slave.yml -vvvv --connection=local -e "python_versions=[2.7, 3.5]" -e "jenkins_group=docker" -e "docker_gid=${DOCKER_GID}" -e "jenkins_id=${JENKINS_UID}" -e "python_enabled=false" --skip-tags restart
# Molecule test
- molecule test
# First run
# Run the role/playbook with ansible-playbook.
# - travis_wait 30
- ansible-playbook -i hosts ./jenkins-slave.yml --connection=local -vvvv -e "python_versions=[2.7, 3.5]" -e "jenkins_group=docker" -e "docker_gid=${DOCKER_GID}" -e "jenkins_id=${JENKINS_UID}" -e "python_enabled=false" --skip-tags restart
# Second run Idempotence test
# Run the role/playbook again, checking to make sure it's idempotent.
- idempotence=$(mktemp)
# - ansible-playbook -i hosts jenkins-slave.yml --connection=local -vvvv -e "python_versions=[2.7, 3.5]" -e "jenkins_group=docker" -e "docker_gid=${DOCKER_GID}" -e "jenkins_id=${JENKINS_UID}" -e "python_enabled=false" --skip-tags restart | tee -a ${idempotence}
# - >
# tail ${idempotence}
# | grep -q 'changed=0.*failed=0'
# | grep -q 'changed=0.*failed=0'
# && (echo 'Idempotence test: pass' && exit 0)
# || (echo 'Idempotence test: fail' && exit 1)
- id -u jenkins | grep -q "no" && (echo "user not found" && exit 1) || (echo "user found" && exit 0)
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/47b10b81867bd0063cf5
- https://galaxy.ansible.com/api/v1/notifications/
on_success: change
on_failure: always
on_start: false
email:
recipients:
on_success: [always|never|change] # default: change
on_failure: [always|never|change] # default: always