Last active
April 28, 2017 14:30
-
-
Save 9seconds/adf9de08db63f2fedaf5a7c1b1017041 to your computer and use it in GitHub Desktop.
Script used to build rannts website on remote machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# vim: set ft=ansible: | |
# Mandatory: copy_back - drectory path without trailing slash | |
# commit_hash - commit to work with | |
- hosts: all | |
become: true | |
gather_facts: false | |
tasks: | |
- name: wait for ssh connectivity | |
local_action: wait_for | |
args: | |
host: "{{ ansible_ssh_host | default(inventory_hostname) }}" | |
port: 22 | |
delay: 10 | |
search_regex: OpenSSH | |
timeout: 300 | |
state: started | |
# and sometimes wait for ssh connectivity is not enough | |
- name: wait until everything up and running | |
pause: | |
seconds: 30 | |
- name: install ansible dependencies | |
raw: > | |
sh -c | |
"apt-get -y update && apt-get -y install --no-install-recommends {{ deps | join(' ') }}" | |
vars: | |
deps: | |
- aptitude | |
- apt-transport-https | |
- ca-certificates | |
- python | |
- python3-apt | |
- python-apt | |
- hosts: all | |
become: true | |
gather_facts: false | |
tasks: | |
- name: add additional apt keys | |
apt_key: | |
url: "{{ item }}" | |
state: present | |
with_items: | |
- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | |
- https://dl.yarnpkg.com/debian/pubkey.gpg | |
- name: add additional apt repositories | |
apt_repository: | |
repo: "{{ item }}" | |
state: present | |
with_items: | |
- deb https://deb.nodesource.com/node_6.x xenial main | |
- deb https://dl.yarnpkg.com/debian/ stable main | |
- name: install build dependencies | |
apt: | |
name: "{{ item }}" | |
install_recommends: no | |
state: present | |
update_cache: yes | |
with_items: | |
- gcc | |
- git | |
- git | |
- libffi-dev | |
- libfontconfig1 | |
- libssl-dev | |
- make | |
- nodejs | |
- python-dev # python is already installed | |
- python-pip | |
- python-setuptools | |
- python-virtualenv | |
- python-wheel | |
- rsync | |
- tar | |
- xz-utils | |
- yarn | |
- name: ensure required paths are absent | |
file: | |
path: "{{ item }}" | |
state: absent | |
with_items: | |
- /build | |
- name: fetch website repository | |
git: | |
repo: https://github.com/rannts/rannts.github.io.git | |
version: "{{ commit_hash }}" | |
dest: /build | |
depth: 1 | |
recursive: yes | |
accept_hostkey: yes | |
- name: install python project dependencies | |
pip: | |
requirements: /build/requirements.txt | |
- name: install node project dependencies | |
command: yarn install --no-progress --non-interactive | |
args: | |
chdir: /build | |
# sometimes node fails to install its dependencies | |
register: yarn_install | |
retries: 3 | |
delay: 2 | |
until: yarn_install.rc == 0 | |
failed_when: false | |
- name: fail if cannot install node dependencies | |
fail: | |
msg: Cannot install node dependencies | |
when: yarn_install.rc != 0 | |
- name: build project | |
command: make {{ item | quote }} | |
args: | |
chdir: /build | |
warn: false | |
with_items: | |
- clean | |
- build | |
- name: copy build back | |
synchronize: | |
src: /build/output/ | |
dest: "{{ copy_back }}/" | |
mode: pull | |
delete: yes | |
perms: yes | |
recursive: yes | |
times: yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment