You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 2
Next »
This is useful if you want to automate deployment and running of MDPM on remote environments. In this example, I'll be controlling a remote machine called 'albatross', a Raspberry Pi with username 'pi'. I'll be building a driver and running it doing all the parameterisations through Ansible.
Setting up inventory
Create a file called hosts
and put in it the IP address of the remote machine:
[albatross]
192.168.1.108 # the IP address of the remote machine
When you have created a playbook, you have to specify using this hosts file by running ansible-playbook -i hosts playbook.yaml
.
Setting up connection credentials
On the remote system, add your SSH public key to ~/.ssh/authorized_keys
.
Tasks for the workhorse
role
Create a file at workhorse/tasks/main.yml
(relative to your base directory) and put the following in it.:
---
# tasks file for workhorse
- name: update apt cache and install common packages
apt:
update_cache: yes
name:
- python3
become: yes
- name: Download and build MercuryDPM
block:
- name: Install MercuryDPM dependencies
apt:
update_cache: yes
name:
- build-essential
- g++
- gfortran
- subversion
- cmake
- graphviz
state: present
become: yes
- name: Copy MercuryDPM build script
copy: src=build_mdpm.sh dest=/opt mode=0755
- name: Download and build MDPM
command: bash /opt/build_mdpm.sh
register: build_output
- name: Print info
debug: msg="{{build_output.stdout}}"
- name: Print errors
debug: msg="{{build_output.stderr}}"
- name: Prepare script that builds and runs driver
template:
src: build_and_run_driver.sh.j2
dest: /opt/MercuryDPM/build_and_run_driver.sh
mode: 0755
- name: Run that script
# TODO https://stackoverflow.com/questions/39347379/ansible-run-command-on-remote-host-in-background
shell: (nohup /opt/MercuryDPM/build_and_run_driver.sh </dev/null >/dev/null 2>&1 &)
# command: bash /opt/MercuryDPM/build_and_run_driver.sh
async: 10
poll: 0
workhorse/files/build_mdpm.sh
: Download MercuryDPM and build MercuryBase
This script downloads MercuryDPM and builds MercuryBase.
#!/bin/bash
set -eux
DPMDIR=/opt/MercuryDPM
declare -a SVN_FLAGS="--non-interactive --trust-server-cert --trust-server-cert-failures=unknown-ca,cn-mismatch,expired,not-yet-valid,other"
declare -a CMAKE_FLAGS="-DCMAKE_BUILD_TYPE=Release -DMercury_BUILD_DOCUMENTATION=OFF -DMercury_BUILD_USER_DIR=OFF -DMercury_Include_Xballs_Support=OFF -DMercury_USE_MPI=OFF"
mkdir -p $DPMDIR && cd $DPMDIR
# CHANGEME if you want to log in as a user so that you can build the USER/ directory
svn checkout https://svn.MercuryDPM.org/SourceCode/Trunk MercurySource --username guest --password '' ${SVN_FLAGS}
cd $DPMDIR/MercurySource
# CHANGEME If you want to use a particular version of MercuryDPM
# SVN_VERSION=5000
# svn update -r $SVN_VERSION --username guest --password '' ${SVN_FLAGS}
mkdir -p $DPMDIR/MercuryBuild && cd $DPMDIR/MercuryBuild
rm -f CMakeCache.txt
# Call cmake twice so that the CMakeDefinitions files are generated
# properly.
cmake ${CMAKE_FLAGS} ../MercurySource
cmake ${CMAKE_FLAGS} ../MercurySource
make clean
make mercury
workhorse/templates/build_and_run_driver.sh.j2
: Build and run your driver
#!/bin/bash
set -eux
DPMDIR=/opt/MercuryDPM
SIMDIR=/mnt/s3gf/{{series}}/{{simulation}}
DRIVER_DIR=$DPMDIR/MercuryBuild/Drivers/{{driver_dir}}
DRIVER_PATH=$DRIVER_DIR/{{driver}}
cd $DRIVER_DIR
make {{driver}}
mkdir -p $SIMDIR
cd $SIMDIR
$DRIVER_PATH {{flags}}