leylines/leylines-ansible/playbook-setup.yml

95 lines
3.5 KiB
YAML
Raw Normal View History

2021-06-15 08:37:57 +00:00
---
- hosts: all
vars:
python_version: 3.9.5
tasks:
- name: install prerequisite packages
become: yes
apt:
name: ["build-essential", "wget", "software-properties-common", "libnss3-dev", "zlib1g-dev",
"libgdbm-dev", "libncurses5-dev", "libssl-dev", "libffi-dev", "libreadline-dev",
"libsqlite3-dev", "libbz2-dev", "libopenblas-dev"]
state: present
update_cache: yes
- name: download build and install python {{ python_version }}
register: pyinstall
changed_when: "'NO_COMPILE_NEEDED' not in pyinstall.stdout"
args:
executable: "/bin/bash"
shell: |
set -eo pipefail
export PATH=$HOME/.local/bin:$PATH
export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH
existing_ver="$(python3 -c 'import sys;print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")')"
if [ "$existing_ver" == "{{ python_version }}" ]; then
echo "NO_COMPILE_NEEDED"
exit
fi
if [ ! -d $HOME/python ]; then
mkdir $HOME/python
fi
cd $HOME/python
wget -O python.tgz https://www.python.org/ftp/python/{{ python_version }}/Python-{{ python_version }}.tgz
tar xf python.tgz
cd Python-{{ python_version }}
# https://bugs.python.org/issue41346
sed -i 's/-j0 //' Makefile.pre.in
# Speed up LTO
sed -i -e "s|-flto |-flto=4 |g" configure configure.ac
export CFLAGS="-O3 -fno-semantic-interposition"
export LDFLAGS="-fno-semantic-interposition"
./configure --prefix=$HOME/.local/ \
--enable-shared \
--with-computed-gotos \
--enable-optimizations \
--with-lto \
--enable-ipv6 \
--with-dbmliborder=gdbm:ndbm \
--enable-loadable-sqlite-extensions \
--with-tzpath=/usr/share/zoneinfo
make -j$(nproc) EXTRA_CFLAGS="$CFLAGS"
make EXTRA_CFLAGS="$CFLAGS" install
- name: Setup dask directory and venv
register: pysetup
changed_when: false # lol
args:
executable: "/bin/bash"
shell: |
set -eo pipefail
export PATH=$HOME/.local/bin:$PATH
export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH
if [ ! -d $HOME/dask ]; then
mkdir $HOME/dask
fi
cd $HOME/dask
python3 -m venv dask-venv
. dask-venv/bin/activate
2021-06-15 09:11:41 +00:00
pip3 install --upgrade dask distributed blosc lz4
2021-06-15 08:37:57 +00:00
if [ "{{ leylines_is_server }}" == "no" ]; then
2021-06-15 09:11:41 +00:00
pip3 install --upgrade numpy scipy pandas scikit-image matplotlib opt_einsum cloudpickle fsspec partd psutil sqlalchemy toolz xxhash
2021-06-15 08:37:57 +00:00
else
pip3 install --upgrade bokeh jupyter-server-proxy
fi
- name: Setup systemd user dir
file:
path: /home/{{ ansible_user }}/.config/systemd/user
mode: 0755
state: directory
- name: Install systemd task
template:
mode: 0644
src: templates/leylines-{% if leylines_is_server == "yes" %}scheduler{% else %}worker{% endif %}.service
dest: /home/{{ ansible_user }}/.config/systemd/user
- name: Enable and start systemd task
systemd:
scope: user
daemon_reload: true
name: leylines-{% if leylines_is_server == "yes" %}scheduler{% else %}worker{% endif %}
enabled: yes
state: restarted