Skip to content

Commit c207c8a

Browse files
authored
Merge pull request #24 from geerlingguy/kporras07-feature/systemd-systems
Kporras07 feature/systemd systems
2 parents 626310f + bde2be7 commit c207c8a

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ env:
1111
- distro: ubuntu1604
1212
init: /lib/systemd/systemd
1313
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
14+
- distro: debian8
15+
init: /lib/systemd/systemd
16+
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
1417
- distro: ubuntu1404
1518
init: /sbin/init
1619
run_opts: "--privileged"
@@ -27,6 +30,9 @@ script:
2730
# Run container in detached state.
2831
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
2932

33+
# Install dependencies.
34+
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml'
35+
3036
# Ansible syntax check.
3137
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
3238

tasks/main.yml

+42-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,24 @@
2323
when: selenium_install_firefox
2424
tags: [configuration, selenium, selenium-firefox]
2525

26+
- name: Add Chrome key (if configured, Debian)
27+
apt_key:
28+
url: "https://dl-ssl.google.com/linux/linux_signing_key.pub"
29+
state: present
30+
when: ansible_os_family == 'Debian' and selenium_install_chrome
31+
tags: [configuration, selenium, selenium-chrome]
32+
33+
- name: Add Chrome repo (if configured, Debian)
34+
apt_repository:
35+
repo: "deb http://dl.google.com/linux/chrome/deb/ stable main"
36+
state: present
37+
update_cache: yes
38+
when: ansible_os_family == 'Debian' and selenium_install_chrome
39+
tags: [configuration, selenium, selenium-chrome]
40+
2641
- name: Install Chrome (if configured, Debian)
2742
apt:
28-
deb: https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
43+
name: google-chrome-stable
2944
state: present
3045
when: ansible_os_family == 'Debian' and selenium_install_chrome
3146
tags: [configuration, selenium, selenium-chrome]
@@ -67,6 +82,32 @@
6782
mode: 0755
6883
tags: [configuration, selenium, selenium-install]
6984

85+
- name: Install systemd unit file (for systemd systems)
86+
template:
87+
src: "selenium-unit.j2"
88+
dest: /etc/systemd/system/selenium.service
89+
owner: root
90+
group: root
91+
mode: 0755
92+
when: >
93+
(ansible_distribution == 'Ubuntu' and ansible_distribution_version.split(".")[0]|int >= 16) or
94+
(ansible_distribution == 'Debian' and ansible_distribution_version.split(".")[0]|int >= 8) or
95+
(ansible_distribution == 'CentOS' and ansible_distribution_version.split(".")[0]|int >= 7) or
96+
(ansible_distribution == 'Fedora')
97+
tags: [configuration, selenium, selenium-install]
98+
99+
- name: Register systemd service status (for systemd systems)
100+
shell: 'systemctl status selenium | grep "active (running)"'
101+
when: >
102+
(ansible_distribution == 'Ubuntu' and ansible_distribution_version.split(".")[0]|int >= 16) or
103+
(ansible_distribution == 'Debian' and ansible_distribution_version.split(".")[0]|int >= 8) or
104+
(ansible_distribution == 'CentOS' and ansible_distribution_version.split(".")[0]|int >= 7) or
105+
(ansible_distribution == 'Fedora')
106+
register: selenium_running
107+
ignore_errors: yes
108+
changed_when: false
109+
70110
- name: Ensure selenium is running
71111
service: name=selenium state=started enabled=yes
72112
tags: [configuration, selenium, selenium-run]
113+
when: selenium_running.failed is defined and selenium_running.failed == true

templates/selenium-unit.j2

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=selenium test framework
3+
After=syslog.target network.target
4+
5+
[Service]
6+
ExecStart=/usr/bin/xvfb-run /usr/bin/java -client -jar {{ selenium_install_dir }}/selenium/selenium-server-standalone-{{ selenium_version }}.jar
7+
Restart=on-failure
8+
RestartSec=20s
9+
10+
[Install]
11+
WantedBy=multi-user.target

tests/requirements.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
- src: geerlingguy.java

tests/test.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44

55
pre_tasks:
66
- name: Update apt cache.
7-
apt: update_cache=yes
7+
apt: update_cache=yes cache_valid_time=3600
88
when: ansible_os_family == 'Debian'
99

10+
- name: Don't install Chrome on old OSes.
11+
set_fact:
12+
selenium_install_firefox: yes
13+
selenium_install_chrome: no
14+
when: >
15+
(ansible_distribution == 'Ubuntu' and ansible_distribution_version == '12.04')
16+
or (ansible_os_family == 'RedHat' and ansible_distribution_version.split('.')[0] == '6')
17+
1018
roles:
19+
- geerlingguy.java
1120
- role_under_test

0 commit comments

Comments
 (0)