2017-07-04 17:46:17 -07:00
---
- name : Configure a Buildbot worker for Zcash CI
hosts : zcash-ci-worker-unix
become : true
gather_facts : False
2017-07-10 08:30:23 -07:00
vars_files :
- vars/default.yml
2017-07-10 09:08:36 -07:00
- vars/buildbot.yml
vars_prompt :
- name : "buildbot_worker_admin"
prompt : "Admin details"
default : "Zcash <sysadmin@z.cash>"
- name : "buildbot_worker_name"
prompt : "Buildbot worker name (provided by ZECC)"
private : no
- name : "buildbot_worker_password"
prompt : "Buildbot worker password (provided by ZECC)"
2017-07-10 08:30:23 -07:00
2017-07-04 17:46:17 -07:00
pre_tasks :
2017-08-07 16:19:23 -07:00
- name : Install Python 2.7 for Ansible and Buildbot
2017-07-10 08:30:23 -07:00
raw : test -e /usr/bin/python || test -e /usr/bin/python2 || test -e /usr/bin/python2.7 || test -e /usr/local/bin/python2.7 || (test -e /usr/bin/apt && apt -qqy update && apt install -qqy python) || (test -e /usr/bin/dnf && dnf install -qqy python2) || (test -e /usr/sbin/pkg && pkg install -qqy python2)
2017-07-04 17:46:17 -07:00
register : output
changed_when :
- output.stdout != ""
- output.stdout != "\r\n"
2017-07-10 08:30:23 -07:00
- name : Check if Python is in the configured location
raw : test -e {{ ansible_python_interpreter }}
2017-07-04 17:46:17 -07:00
ignore_errors : true
2017-07-10 08:30:23 -07:00
register : python_check
when : ansible_python_interpreter is defined
- name : Fail if configured Python is unavailable
fail :
2017-08-07 16:19:23 -07:00
msg : "Python is not accessible at {{ ansible_python_interpreter }} on this host! Please set the inventory variable 'ansible_python_interpreter' to the location of the Python 2.7 binary."
2017-07-10 08:30:23 -07:00
when : ansible_python_interpreter is defined and python_check.rc == 1
- name : Check if Python is in the default location
raw : test -e /usr/bin/python
ignore_errors : true
register : python_check
when : ansible_python_interpreter is undefined
- name : Fail if default Python is unavailable
fail :
2017-08-07 16:19:23 -07:00
msg : Python is not accessible at /usr/bin/python on this host! Please set the inventory variable 'ansible_python_interpreter' to the location of the Python 2.7 binary.
2017-07-10 08:30:23 -07:00
when : ansible_python_interpreter is undefined and python_check.rc == 1
2017-07-04 17:46:17 -07:00
- name : Gathering Facts
setup :
2017-10-28 15:22:15 -07:00
tags : deps
2017-07-04 17:46:17 -07:00
2017-08-07 16:19:23 -07:00
- name : Fail if Python is the wrong version
fail :
msg : "The Python binary at {{ ansible_python.executable }} is version {{ ansible_python_version }}! Please set the inventory variable 'ansible_python_interpreter' to the location of the Python 2.7 binary."
when : ansible_python.version.major != 2 or ansible_python.version.minor != 7
2017-07-04 17:46:17 -07:00
tasks :
- name : Get dependencies for distribution
include_vars : "{{ item }}"
with_first_found :
- files :
- "vars/{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
- "vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version | int }}.yml"
- "vars/{{ ansible_distribution }}.yml"
- "vars/{{ ansible_os_family }}.yml"
skip : true
2017-10-28 15:22:15 -07:00
tags : deps
2017-07-04 17:46:17 -07:00
- name : Collate dependencies
set_fact :
package_deps : "{{ buildbot_deps + fetch_deps + conf_deps + build_deps + link_deps + dist_deps }}"
python_modules : "{{ buildbot_modules + rpc_test_modules }}"
2017-10-28 15:22:15 -07:00
tags : deps
2017-07-04 17:46:17 -07:00
2017-10-19 22:23:25 -07:00
- name : Install Homebrew [MacOSX]
include : tasks/install-brew.yml
when : ansible_distribution == 'MacOSX'
2017-10-28 15:22:15 -07:00
tags : deps
2017-10-19 22:23:25 -07:00
2017-08-03 06:36:08 -07:00
- name : Update rolling release [Arch Linux]
pacman :
update_cache : yes
upgrade : yes
when : ansible_distribution == 'Archlinux'
2017-10-28 15:22:15 -07:00
tags : deps
2017-08-03 06:36:08 -07:00
2017-07-04 17:46:17 -07:00
- name : Install required packages
package :
name : "{{ item }}"
state : present
with_items : "{{ package_deps }}"
2017-10-19 22:23:25 -07:00
become_user : "{{ ansible_ssh_user if ansible_distribution == 'MacOSX' else 'root' }}"
2017-10-28 15:22:15 -07:00
tags : deps
2017-07-04 17:46:17 -07:00
2017-10-19 22:23:25 -07:00
- name : Install pip [CentOS, MacOSX]
2017-08-09 14:41:48 -07:00
include : tasks/install-pip.yml
2017-10-19 22:23:25 -07:00
when : ansible_distribution in ['CentOS', 'MacOSX']
2017-08-09 14:41:48 -07:00
2017-10-19 19:34:11 -07:00
- name : Install required Python system modules
2017-07-04 17:46:17 -07:00
pip :
name : "{{ item }}"
state : latest
2017-10-19 22:23:25 -07:00
executable : "{{ '/usr/local/bin/pip' if ansible_distribution == 'MacOSX' else omit }}"
2017-10-19 19:34:11 -07:00
with_items : "{{ system_modules }}"
2017-07-10 09:08:36 -07:00
- name : Set up the Buildbot worker user
user :
name : "{{ buildbot_worker_user }}"
comment : Buildbot worker
shell : /bin/bash
state : present
2017-10-19 17:37:46 -07:00
- name : Get absolute path to Buildbot worker home directory
command : echo ~
register : homedir
become_user : "{{ buildbot_worker_user }}"
- name : Save absolute path to Buildbot worker home directory
set_fact :
buildbot_worker_dir : "{{ homedir.stdout }}"
2017-10-19 19:34:11 -07:00
- name : Install required Python modules
pip :
name : "{{ item }}"
state : latest
virtualenv : "~{{ buildbot_worker_user }}/venv"
2017-10-19 22:23:25 -07:00
virtualenv_command : "{{ '/usr/local/bin/virtualenv' if ansible_distribution == 'MacOSX' else omit }}"
2017-10-19 19:34:11 -07:00
with_items : "{{ python_modules }}"
become_user : "{{ buildbot_worker_user }}"
notify : restart buildbot-worker
2017-07-10 09:08:36 -07:00
- name : Create Buildbot worker
command : >
2017-10-19 19:34:11 -07:00
~{{ buildbot_worker_user }}/venv/bin/buildbot-worker create-worker ~/{{ buildbot_worker_name }}
2017-07-10 09:08:36 -07:00
{{ buildbot_master_host }}:{{ buildbot_master_port }}
{{ buildbot_worker_name|quote }} {{ buildbot_worker_password|quote }}
args :
creates : "~/{{ buildbot_worker_name }}/buildbot.tac"
become_user : "{{ buildbot_worker_user }}"
- name : Set admin details for Buildbot worker
copy :
content : "{{ buildbot_worker_admin }}"
2017-08-01 04:35:58 -07:00
dest : "~{{ buildbot_worker_user }}/{{ buildbot_worker_name }}/info/admin"
owner : "{{ buildbot_worker_user }}"
2017-10-19 22:23:25 -07:00
group : "{{ omit if ansible_distribution == 'MacOSX' else buildbot_worker_user }}"
2017-08-01 04:35:58 -07:00
mode : "0644"
2017-07-10 09:08:36 -07:00
- name : Set host details for Buildbot worker
template :
2017-07-14 10:24:01 -07:00
src : "{{ buildbot_worker_host_template }}"
2017-08-01 04:35:58 -07:00
dest : "~{{ buildbot_worker_user }}/{{ buildbot_worker_name }}/info/host"
owner : "{{ buildbot_worker_user }}"
2017-10-19 22:23:25 -07:00
group : "{{ omit if ansible_distribution == 'MacOSX' else buildbot_worker_user }}"
2017-08-01 04:35:58 -07:00
mode : "0644"
2017-07-10 09:08:36 -07:00
2017-10-19 19:34:11 -07:00
- name : Install custom bashrc for virtualenv
copy :
src : bashrc
dest : "~{{ buildbot_worker_user }}/.bashrc"
owner : "{{ buildbot_worker_user }}"
2017-10-19 22:23:25 -07:00
group : "{{ omit if ansible_distribution == 'MacOSX' else buildbot_worker_user }}"
2017-10-19 19:34:11 -07:00
mode : "0644"
2017-07-10 09:08:36 -07:00
- name : Copy Buildbot worker systemd service unit
template :
src : templates/buildbot-worker.service.j2
dest : "/etc/systemd/system/buildbot-worker.service"
owner : root
group : root
mode : "0644"
2017-10-19 22:23:25 -07:00
when : ansible_distribution != 'MacOSX'
2017-07-10 09:08:36 -07:00
notify : reload systemd
2017-10-19 22:23:25 -07:00
- name : Copy Buildbot worker launchd service unit
template :
src : templates/buildbot-worker.plist.j2
dest : "/Library/LaunchDaemons/net.buildbot.worker.plist"
owner : root
group : wheel
mode : "0644"
when : ansible_distribution == 'MacOSX'
- name : Start Buildbot worker
2017-07-10 09:08:36 -07:00
service :
name : buildbot-worker
state : started
enabled : yes
2017-10-19 22:23:25 -07:00
when : ansible_distribution != 'MacOSX'
- name : Load Buildbot worker service [MacOSX]
command : launchctl load /Library/LaunchDaemons/net.buildbot.worker.plist
when : ansible_distribution == 'MacOSX'
- name : Start Buildbot worker [MacOSX]
command : launchctl start net.buildbot.worker
when : ansible_distribution == 'MacOSX'
2017-07-10 09:08:36 -07:00
handlers :
- name : restart buildbot-worker
service :
name : buildbot-worker
state : restarted
- name : reload systemd
command : /bin/systemctl daemon-reload