diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..278f0ee --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: Ansible CI with Docker + +on: [push, pull_request] + +jobs: + test-ansible: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Lint Ansible Playbooks ๐Ÿงน + uses: docker://ansible/ansible-lint:latest + with: + args: 'ansible/playbooks/' + + - name: Check Ansible Playbook Syntax โœ… + run: | + docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace ansible/ansible:latest bash -c " + for playbook in ansible/playbooks/*.yml; do + echo 'Checking syntax of' \$playbook + ansible-playbook -i ansible/inventory.ini --syntax-check \$playbook + done + " diff --git a/ansible/README.md b/ansible/README.md new file mode 100644 index 0000000..a14f650 --- /dev/null +++ b/ansible/README.md @@ -0,0 +1,11 @@ +# Ansible playbooks for preCICE + +This repository contains a set of Ansible playbooks that automate the provisioning of a system with preCICE and several adapters and further tools installed. These playbooks are converted from the original shell scripts, making the setup process modular, idempotent, and more maintainable. + +To run a specific playbook, get Ansible (e.g., `sudo apt install ansible`) and execute from this directory, for example: + +```shell +ansible-playbook -i inventory.ini playbooks/install-basics.yml +``` + +To check (dry-run) the playbooks, use the `--check --diff` flags. diff --git a/ansible/inventory.ini b/ansible/inventory.ini new file mode 100644 index 0000000..217b502 --- /dev/null +++ b/ansible/inventory.ini @@ -0,0 +1,5 @@ +[local] +localhost ansible_connection=local + +[remote] +# Example: server1 ansible_host=192.168.1.100 ansible_user=youruser diff --git a/ansible/playbooks/install-aste.yml b/ansible/playbooks/install-aste.yml new file mode 100644 index 0000000..cbbd749 --- /dev/null +++ b/ansible/playbooks/install-aste.yml @@ -0,0 +1,70 @@ +--- +- name: Install aste with dependencies + hosts: localhost + connection: local + become: true + vars: + user_home: "{{ lookup('env', 'HOME') }}" + aste_repo_url: "https://github.com/precice/aste.git" + aste_path: "{{ user_home }}/aste" + aste_venv_path: "{{ user_home }}/python-venvs/aste" + + tasks: + - name: Install system dependencies for aste + apt: + name: + - libvtk9-dev + - libvtk9-qt-dev + - libmetis-dev + - python3-venv + - python3-pip + state: present + update_cache: yes + + - name: Create Python virtual environment for aste + become: false + command: python3 -m venv {{ aste_venv_path }} + args: + creates: "{{ aste_venv_path }}/bin/activate" + + - name: Install Python packages in aste venv + become: false + shell: | + source {{ aste_venv_path }}/bin/activate + pip install --upgrade pip + pip install sympy scipy jinja2 + args: + executable: /bin/bash + + - name: Clone aste repository + become: false + git: + repo: "{{ aste_repo_url }}" + dest: "{{ aste_path }}" + version: master + depth: 1 + update: yes + + - name: Build aste project + become: false + shell: | + mkdir -p build && cd build + cmake .. + make -j $(nproc) + args: + chdir: "{{ aste_path }}" + executable: /bin/bash + + - name: Add aste build path to PATH in .bashrc + become: false + lineinfile: + path: "{{ user_home }}/.bashrc" + line: 'export PATH="${HOME}/aste/build:${PATH}"' + insertafter: EOF + + - name: Add aste build path to LD_LIBRARY_PATH in .bashrc + become: false + lineinfile: + path: "{{ user_home }}/.bashrc" + line: 'export LD_LIBRARY_PATH="${HOME}/aste/build:${LD_LIBRARY_PATH}"' + insertafter: EOF diff --git a/ansible/playbooks/install-basics.yml b/ansible/playbooks/install-basics.yml new file mode 100644 index 0000000..bf8e9c3 --- /dev/null +++ b/ansible/playbooks/install-basics.yml @@ -0,0 +1,93 @@ +--- +- name: Install a dekstop environment, basic tools, and VM guest additions + hosts: all + become: true + + vars: + keyboard_layout: us + hostname: precicevm + + pre_tasks: + # Some repos are a bit fragile and need multiple download tries. + - name: Set correct APT retry config + copy: + dest: /etc/apt/apt.conf.d/80-retries + content: | + Acquire::Retries "4"; + force: yes + + tasks: + # We (may) need the multiverse repository for the VBox Guest Additions + - name: Add multiverse repository + apt_repository: + repo: "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }} multiverse" + state: present + filename: multiverse + + - name: Update APT cache + apt: + update_cache: yes + + - name: Upgrade packages + apt: + upgrade: yes + force_apt_get: yes + + - name: Install Xfce desktop environment + apt: + name: xubuntu-core + state: present + + - name: Install GUI and terminal apps + apt: + name: + - thunar + - xfce4-terminal + - terminator + - bash-completion + - tree + - atril + - firefox + - firefox-locale-en + - baobab + - catfish + state: present + + - name: Install Python + apt: + name: + - python3-dev + - pipx + - python-is-python3 + - python3-venv + state: present + + - name: Install VirtualBox Guest Additions + apt: + name: + - virtualbox-guest-utils + - virtualbox-guest-x11 + state: present + + - name: Create Desktop directory if not present + file: + path: "{{ ansible_env.HOME }}/Desktop" + state: directory + mode: '0755' + + - name: Set keyboard layout + lineinfile: + path: /etc/default/keyboard + regexp: '^XKBLAYOUT=' + line: 'XKBLAYOUT="{{ keyboard_layout }}"' + + - name: Copy keyboard settings shortcut to Desktop + copy: + src: /usr/share/applications/xfce-keyboard-settings.desktop + dest: "{{ ansible_env.HOME }}/Desktop/" + remote_src: yes + mode: '0755' + + - name: Set hostname + hostname: + name: "{{ hostname }}" diff --git a/ansible/playbooks/install-calculix.yml b/ansible/playbooks/install-calculix.yml new file mode 100644 index 0000000..5e6c8fc --- /dev/null +++ b/ansible/playbooks/install-calculix.yml @@ -0,0 +1,65 @@ +--- +- name: Install CalculiX and the preCICE adapter + hosts: all + become: true + vars: + user_home: "{{ lookup('env', 'HOME') }}" + calculix_url: "http://www.dhondt.de/ccx_2.20.src.tar.bz2" + calculix_tarball: "ccx_2.20.src.tar.bz2" + calculix_dir: "ccx_2.20" + adapter_repo_url: "https://github.com/precice/calculix-adapter.git" + adapter_path: "{{ user_home }}/calculix-adapter" + + tasks: + - name: Install dependencies for CalculiX + apt: + name: + - libarpack2-dev + - libspooles-dev + - libyaml-cpp-dev + state: present + update_cache: yes + + - name: Download CalculiX source tarball + become: false + get_url: + url: "{{ calculix_url }}" + dest: "{{ user_home }}/{{ calculix_tarball }}" + mode: '0644' + + - name: Extract CalculiX source + become: false + unarchive: + src: "{{ user_home }}/{{ calculix_tarball }}" + dest: "{{ user_home }}" + remote_src: true + + - name: Remove CalculiX tarball + become: false + file: + path: "{{ user_home }}/{{ calculix_tarball }}" + state: absent + + - name: Clone CalculiX adapter repository + become: false + git: + repo: "{{ adapter_repo_url }}" + dest: "{{ adapter_path }}" + version: master + depth: 1 + update: yes + + - name: Build CalculiX adapter + become: false + shell: | + make -j $(nproc) ADDITIONAL_FFLAGS=-fallow-argument-mismatch + args: + chdir: "{{ adapter_path }}" + executable: /bin/bash + + - name: Add CalculiX adapter to PATH in .bashrc + become: false + lineinfile: + path: "{{ user_home }}/.bashrc" + line: 'export PATH="{{ user_home }}/calculix-adapter/bin:$PATH"' + insertafter: EOF diff --git a/ansible/playbooks/install-code_aster.yml b/ansible/playbooks/install-code_aster.yml new file mode 100644 index 0000000..bd415af --- /dev/null +++ b/ansible/playbooks/install-code_aster.yml @@ -0,0 +1,151 @@ +--- +- name: Install Code_Aster and its preCICE adapter + hosts: all + become: true + vars: + aster_url: "https://www.code-aster.org/FICHIERS/aster-full-src-14.6.0-1.noarch.tar.gz" + aster_tarball: "aster-full-src-14.6.0-1.noarch.tar.gz" + aster_extract_dir: "aster-full-src-14.6.0" + aster_install_path: "{{ ansible_env.HOME }}/code_aster" + adapter_repo_url: "https://github.com/precice/code_aster-adapter.git" + adapter_path: "{{ ansible_env.HOME }}/code_aster-adapter" + tutorial_path: "{{ ansible_env.HOME }}/tutorials/flow-over-heated-plate-steady-state" + + tasks: + - name: Install Code_Aster dependencies + apt: + name: + - bison + - cmake + - make + - flex + - g++ + - gcc + - gfortran + - grace + - liblapack-dev + - libblas-dev + - libboost-numpy-dev + - libboost-python-dev + - python3 + - python3-dev + - python3-numpy + - tk + - zlib1g-dev + state: present + update_cache: yes + + - name: Download Code_Aster tarball + become: false + get_url: + url: "{{ aster_url }}" + dest: "{{ ansible_env.HOME }}/{{ aster_tarball }}" + mode: '0644' + + - name: Extract Code_Aster source + become: false + unarchive: + src: "{{ ansible_env.HOME }}/{{ aster_tarball }}" + dest: "{{ ansible_env.HOME }}" + remote_src: yes + + - name: Install Code_Aster to user directory + become: false + shell: | + yes | python3 setup.py install --prefix="{{ aster_install_path }}" + args: + chdir: "{{ ansible_env.HOME }}/{{ aster_extract_dir }}" + executable: /bin/bash + + - name: Clean up extracted Code_Aster source + become: false + file: + path: "{{ ansible_env.HOME }}/{{ aster_extract_dir }}" + state: absent + + - name: Add Code_Aster to .bashrc + become: false + lineinfile: + path: "{{ ansible_env.HOME }}/.bashrc" + line: '. {{ aster_install_path }}/etc/codeaster/profile.sh' + insertafter: EOF + + - name: Clone Code_Aster adapter + become: false + git: + repo: "{{ adapter_repo_url }}" + dest: "{{ adapter_path }}" + version: master + depth: 1 + update: yes + + - name: Symlink adapter.py to Code_Aster Execution directory + become: false + file: + src: "{{ adapter_path }}/cht/adapter.py" + dest: "{{ aster_install_path }}/14.6/lib/aster/Execution/adapter.py" + state: link + + - name: Remove tests from Code_Aster to save space + become: false + file: + path: "{{ aster_install_path }}/14.6/share/aster/tests" + state: absent + + - name: Remove documentation from Code_Aster to save space + become: false + file: + path: "{{ aster_install_path }}/public/med-4.00/share/doc" + state: absent + + - name: Update exchange directory path in precice-config.xml + become: false + replace: + path: "{{ tutorial_path }}/precice-config.xml" + regexp: 'exchange-directory=".."' + replace: 'exchange-directory="{{ tutorial_path }}"' + + - name: Generate solid.export file for solid-codeaster + become: false + shell: | + if [ ! -f solid.export ]; then + cat < solid.export +P actions make_etude +P aster_root /code_aster +P consbtc oui +P debug nodebug +P display precicevm:0 +P follow_output yes +P mclient precicevm +P memjob 524288 +P memory_limit 512.0 +P mode interactif +P ncpus 1 +P nomjob linear-thermic +P origine salomemeca_asrun 1.10.0 +P protocol_copyfrom asrun.plugins.server.SCPServer +P protocol_copyto asrun.plugins.server.SCPServer +P protocol_exec asrun.plugins.server.SSHServer +P rep_trav /tmp/root-23129e00f0db-interactif_4800 +P serveur localhost +P soumbtc oui +P time_limit 600.0 +P tpsjob 11 +P uclient precicevm +P username precicevm +P version stable +A memjeveux 64.0 +A tpmax 600.0 +F comm ${HOME}/code_aster-adapter/cht/adapter.comm D 1 +F libr $(pwd)/config.comm D 90 +F libr $(pwd)/def.comm D 91 +F mmed $(pwd)/solid.mmed D 20 +R repe $(pwd)/REPE_OUT D 0 +R repe $(pwd)/REPE_OUT R 0 +F mess $(pwd)/solid.mess R 6 +F resu $(pwd)/solid.resu R 8 +EOF + fi + args: + chdir: "{{ tutorial_path }}/solid-codeaster" + executable: /bin/bash diff --git a/ansible/playbooks/install-config-visualizer.yml b/ansible/playbooks/install-config-visualizer.yml new file mode 100644 index 0000000..5fa1a53 --- /dev/null +++ b/ansible/playbooks/install-config-visualizer.yml @@ -0,0 +1,91 @@ +--- +- name: Install preCICE Config Visualizer CLI and GUI + hosts: all + become: true + vars: + user_home: "/home/vagrant" + visualizer_version: "1.1.3" + visualizer_gui_version: "0.1.0" + pipx_bin_path: "{{ user_home }}/.local/bin" + pipx_venv_gui_path: "{{ user_home }}/.local/share/pipx/venvs/precice-config-visualizer-gui/share" + + tasks: + - name: Install CLI dependencies (graphviz) + apt: + name: graphviz + state: present + update_cache: yes + + - name: Install system dependencies for GUI and PyGObject + apt: + name: + - build-essential + - pkg-config + - python3-dev + - libcairo2-dev + - libgirepository1.0-dev + - libglib2.0-dev + - libffi-dev # โœ… REQUIRED FOR PyGObject + - gir1.2-gtk-3.0 + - python3-gi + - python3-cairo + - meson + - ninja-build + state: present + update_cache: yes + + - name: Ensure pipx is installed + apt: + name: pipx + state: present + + - name: Install preCICE Config Visualizer CLI + become: false + shell: | + pipx install --force precice-config-visualizer=={{ visualizer_version }} + environment: + PATH: "{{ pipx_bin_path }}:{{ ansible_env.PATH }}" + args: + executable: /bin/bash + + - name: Install preCICE Config Visualizer GUI + become: false + shell: | + pipx install --force precice-config-visualizer-gui=={{ visualizer_gui_version }} + environment: + PATH: "{{ pipx_bin_path }}:{{ ansible_env.PATH }}" + args: + executable: /bin/bash + + - name: Add pipx bin path to PATH in .bashrc + become: false + lineinfile: + path: "{{ user_home }}/.bashrc" + line: 'export PATH="{{ pipx_bin_path }}:${PATH}"' + insertafter: EOF + + - name: Create user application and icon directories + become: false + file: + path: "{{ item }}" + state: directory + mode: '0755' + loop: + - "{{ user_home }}/.local/share/applications" + - "{{ user_home }}/.local/share/icons" + + - name: Copy GUI desktop file + become: false + copy: + src: "{{ pipx_venv_gui_path }}/applications/org.precice.config_visualizer.desktop" + dest: "{{ user_home }}/.local/share/applications/org.precice.config_visualizer.desktop" + remote_src: yes + mode: '0644' + + - name: Copy GUI icon file + become: false + copy: + src: "{{ pipx_venv_gui_path }}/icons/hicolor/scalable/apps/org.precice.config_visualizer.svg" + dest: "{{ user_home }}/.local/share/icons/org.precice.config_visualizer.svg" + remote_src: yes + mode: '0644' diff --git a/ansible/playbooks/install-dealii.yml b/ansible/playbooks/install-dealii.yml new file mode 100644 index 0000000..5b3cbb2 --- /dev/null +++ b/ansible/playbooks/install-dealii.yml @@ -0,0 +1,52 @@ +--- +- name: Install deal.II and the preCICE deal.II adapter + hosts: all + become: true + + vars: + adapter_repo_url: "https://github.com/precice/dealii-adapter.git" + + tasks: + - name: Update apt cache + apt: + update_cache: yes + + - name: Install libdeal.ii-dev package + apt: + name: libdeal.ii-dev + state: present + + - name: Set adapter path using actual user directory + set_fact: + adapter_path: "{{ lookup('env', 'HOME') }}/dealii-adapter" + become: false + + - name: Debug adapter path + become: false + debug: + msg: "Adapter will be cloned to: {{ adapter_path }}" + + - name: Clone deal.II adapter repo if not present + become: false + git: + repo: "{{ adapter_repo_url }}" + dest: "{{ adapter_path }}" + version: master + depth: 1 + update: yes + + - name: Build the deal.II adapter + become: false + shell: | + cmake . + make -j $(nproc) + args: + chdir: "{{ adapter_path }}" + executable: /bin/bash + + - name: Add deal.II adapter path to PATH in .bashrc + become: false + lineinfile: + path: "{{ lookup('env', 'HOME') }}/.bashrc" + line: 'export PATH="{{ adapter_path }}:${PATH}"' + insertafter: EOF diff --git a/ansible/playbooks/install-devel.yml b/ansible/playbooks/install-devel.yml new file mode 100644 index 0000000..6dfea65 --- /dev/null +++ b/ansible/playbooks/install-devel.yml @@ -0,0 +1,19 @@ +- name: Set up development environment + hosts: all + become: true + tasks: + - name: Install development tools and editors + apt: + name: + - build-essential + - git + - cmake + - cmake-curses-gui + - cargo + - nano + - vim + - gedit + - meld + - ipython3 + state: present + update_cache: yes diff --git a/ansible/playbooks/install-dune.yml b/ansible/playbooks/install-dune.yml new file mode 100644 index 0000000..af3db3a --- /dev/null +++ b/ansible/playbooks/install-dune.yml @@ -0,0 +1,117 @@ +--- +- name: Install DUNE, DuMux, and preCICE adapters + hosts: all + gather_facts: yes + vars: + home_dir: "{{ ansible_env.HOME }}" + dune_dir: "{{ home_dir }}/dune-dumux" + dune_modules: + - { name: dune-common, url: https://gitlab.dune-project.org/core/dune-common.git, branch: v2.9.1 } + - { name: dune-istl, url: https://gitlab.dune-project.org/core/dune-istl.git, branch: v2.9.1 } + - { name: dune-localfunctions, url: https://gitlab.dune-project.org/core/dune-localfunctions.git, branch: v2.9.1 } + - { name: dune-grid, url: https://gitlab.dune-project.org/core/dune-grid.git, branch: v2.9.1 } + - { name: dune-geometry, url: https://gitlab.dune-project.org/core/dune-geometry.git, branch: v2.9.1 } + - { name: dune-foamgrid, url: https://gitlab.dune-project.org/extensions/dune-foamgrid.git, branch: 2.9.1 } + - { name: dune-functions, url: https://gitlab.dune-project.org/staging/dune-functions.git, branch: v2.9.1 } + - { name: dune-typetree, url: https://gitlab.dune-project.org/staging/dune-typetree.git, branch: v2.9.1 } + - { name: dune-uggrid, url: https://gitlab.dune-project.org/staging/dune-uggrid.git, branch: v2.9.1 } + elastodynamics_repo: "https://github.com/maxfirmbach/dune-elastodynamics.git" + dune_adapter_repo: "https://github.com/precice/dune-adapter.git" + dumux_repo: "https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git" + dumux_adapter_repo: "https://github.com/precice/dumux-adapter.git" + + tasks: + - name: Install git if not present + become: true + apt: + name: git + state: present + update_cache: yes + + - name: Ensure dune-dumux directory exists + file: + path: "{{ dune_dir }}" + state: directory + + - name: Clone core DUNE modules + git: + repo: "{{ item.url }}" + dest: "{{ dune_dir }}/{{ item.name }}" + version: "{{ item.branch }}" + depth: 1 + update: yes + loop: "{{ dune_modules }}" + + - name: Clone dune-elastodynamics + git: + repo: "{{ elastodynamics_repo }}" + dest: "{{ dune_dir }}/dune-elastodynamics" + version: master + depth: 1 + update: yes + + - name: Pull latest dune-elastodynamics + shell: git pull + args: + chdir: "{{ dune_dir }}/dune-elastodynamics" + + - name: Clone dune-adapter + git: + repo: "{{ dune_adapter_repo }}" + dest: "{{ dune_dir }}/dune-adapter" + version: main + depth: 1 + update: yes + + - name: Pull latest dune-adapter + shell: git pull + args: + chdir: "{{ dune_dir }}/dune-adapter/dune-precice" + + - name: Build all DUNE modules with dunecontrol + shell: ./dune-common/bin/dunecontrol all + args: + chdir: "{{ dune_dir }}" + + - name: Clone DuMux repository + git: + repo: "{{ dumux_repo }}" + dest: "{{ dune_dir }}/dumux" + version: releases/3.8 + depth: 1 + update: yes + + - name: Build DuMux with dunecontrol + shell: | + CMAKE_FLAGS="$CMAKE_FLAGS -DCMAKE_DISABLE_FIND_PACKAGE_Kokkos=TRUE" ./dune-common/bin/dunecontrol --only=dumux all + args: + chdir: "{{ dune_dir }}" + executable: /bin/bash + + - name: Clone DuMux adapter + git: + repo: "{{ dumux_adapter_repo }}" + dest: "{{ dune_dir }}/dumux-adapter" + version: v2.0.0 + depth: 1 + update: yes + + - name: Build DuMux adapter with dunecontrol + shell: | + CMAKE_FLAGS="$CMAKE_FLAGS -DCMAKE_DISABLE_FIND_PACKAGE_Kokkos=TRUE" ./dune-common/bin/dunecontrol --only=dumux-precice all + args: + chdir: "{{ dune_dir }}" + executable: /bin/bash + + - name: Add DUNE_CONTROL_PATH to .bashrc + lineinfile: + path: "{{ home_dir }}/.bashrc" + line: 'export DUNE_CONTROL_PATH="{{ dune_dir }}"' + insertafter: EOF + + - name: Copy DUNE example to tutorials + copy: + src: "{{ dune_dir }}/dune-adapter/dune-precice-howto/build-cmake/examples/dune-perpendicular-flap" + dest: "{{ home_dir }}/tutorials/perpendicular-flap/solid-dune" + remote_src: yes + mode: '0755' diff --git a/ansible/playbooks/install-fenics.yml b/ansible/playbooks/install-fenics.yml new file mode 100644 index 0000000..6af49d9 --- /dev/null +++ b/ansible/playbooks/install-fenics.yml @@ -0,0 +1,67 @@ +--- +- name: Install FEniCS and the FEniCS-preCICE adapter + hosts: all + become: true + + vars: + distro_user: "{{ ansible_user_id }}" + + tasks: + - name: Get actual user home directory (not root) + become: false + set_fact: + distro_user_home: "{{ lookup('env', 'HOME') }}" + + - name: Set fenics venv path + set_fact: + fenics_venv_path: "{{ distro_user_home }}/python-venvs/fenicsprecice" + + - name: Install software-properties-common for add-apt-repository + apt: + name: software-properties-common + state: present + update_cache: yes + + - name: Add FEniCS APT repository + apt_repository: + repo: ppa:fenics-packages/fenics + state: present + + - name: Update APT cache after adding FEniCS repo + apt: + update_cache: yes + + - name: Install FEniCS without recommended packages + apt: + name: fenics + state: present + install_recommends: no + + - name: Install Python venv module and pip + apt: + name: + - python3-venv + - python3-pip + state: present + + - name: Ensure directory for virtual environments exists + become: false + file: + path: "{{ distro_user_home }}/python-venvs" + state: directory + mode: '0755' + + - name: Create virtual environment for FEniCS-preCICE + become: false + command: python3 -m venv {{ fenics_venv_path }} + args: + creates: "{{ fenics_venv_path }}/bin/activate" + + - name: Install fenicsprecice in virtual environment + become: false + shell: | + source {{ fenics_venv_path }}/bin/activate + pip install --upgrade pip + pip install fenicsprecice + args: + executable: /bin/bash diff --git a/ansible/playbooks/install-fmiprecice.yml b/ansible/playbooks/install-fmiprecice.yml new file mode 100644 index 0000000..afd863e --- /dev/null +++ b/ansible/playbooks/install-fmiprecice.yml @@ -0,0 +1,17 @@ +--- +- name: Install FMI-preCICE runner via pipx + hosts: all + become: true + + tasks: + - name: Ensure pipx is installed + apt: + name: pipx + state: present + update_cache: yes + + - name: Install fmiprecice using pipx + become: false + shell: pipx install fmiprecice + args: + executable: /bin/bash diff --git a/ansible/playbooks/install-julia-bindings.yml b/ansible/playbooks/install-julia-bindings.yml new file mode 100644 index 0000000..68ca288 --- /dev/null +++ b/ansible/playbooks/install-julia-bindings.yml @@ -0,0 +1,47 @@ +--- +- name: Install Julia and PreCICE Julia bindings + hosts: all + become: true + + tasks: + - name: Install python3-venv and pip + apt: + name: + - python3-venv + - python3-pip + state: present + update_cache: yes + +- name: Configure Julia environment as normal user + hosts: all + become: false + vars: + julia_venv_base: "{{ ansible_env.HOME }}/python-venvs" + julia_venv_path: "{{ julia_venv_base }}/julia" + + tasks: + - name: Ensure directory for virtual environments exists + file: + path: "{{ julia_venv_base }}" + state: directory + mode: '0755' + + - name: Create virtual environment for Julia + command: python3 -m venv {{ julia_venv_path }} + args: + creates: "{{ julia_venv_path }}/bin/activate" + + - name: Install jill and Julia via jill + shell: | + source {{ julia_venv_path }}/bin/activate + pip install --upgrade pip + pip install jill + jill install --confirm + args: + executable: /bin/bash + + - name: Install PreCICE Julia bindings + shell: | + ~/.local/bin/julia -e 'using Pkg; Pkg.add("PreCICE")' + args: + executable: /bin/bash diff --git a/ansible/playbooks/install-micro-manager.yml b/ansible/playbooks/install-micro-manager.yml new file mode 100644 index 0000000..cb27032 --- /dev/null +++ b/ansible/playbooks/install-micro-manager.yml @@ -0,0 +1,17 @@ +--- +- name: Install micro-manager-preCICE via pipx + hosts: all + become: true + + tasks: + - name: Ensure pipx is installed + apt: + name: pipx + state: present + update_cache: yes + + - name: Install micro-manager-precice using pipx + become: false + shell: pipx install micro-manager-precice + args: + executable: /bin/bash diff --git a/ansible/playbooks/install-openfoam.yml b/ansible/playbooks/install-openfoam.yml new file mode 100644 index 0000000..7445598 --- /dev/null +++ b/ansible/playbooks/install-openfoam.yml @@ -0,0 +1,61 @@ +--- +- name: Install OpenFOAM system-wide + hosts: all + become: true + + tasks: + - name: Add OpenFOAM signing key and repository + shell: wget -q -O - https://dl.openfoam.com/add-debian-repo.sh | bash + args: + executable: /bin/bash + + - name: Install OpenFOAM v2312 + apt: + name: openfoam2312-dev + state: present + +- name: Setup OpenFOAM-preCICE for local user + hosts: all + become: false + vars: + openfoam_version: openfoam2312 + + tasks: + - name: Set actual user home + ansible.builtin.set_fact: + actual_home: "{{ ansible_env.HOME }}" + + - name: Enable OpenFOAM by default in .bashrc + lineinfile: + path: "{{ actual_home }}/.bashrc" + line: ". /usr/lib/openfoam/{{ openfoam_version }}/etc/bashrc" + create: yes + + - name: Clone OpenFOAM-preCICE adapter repository + git: + repo: https://github.com/precice/openfoam-adapter.git + dest: "{{ actual_home }}/openfoam-adapter" + version: master + depth: 1 + update: yes + + - name: Build OpenFOAM-preCICE adapter + shell: | + source /usr/lib/openfoam/{{ openfoam_version }}/etc/bashrc + ./Allclean + ./Allwmake + args: + chdir: "{{ actual_home }}/openfoam-adapter" + executable: /bin/bash + environment: + FOAM_INST_DIR: /usr/lib/openfoam + + - name: Build OpenFOAM solver in tutorial + shell: | + source /usr/lib/openfoam/{{ openfoam_version }}/etc/bashrc + wmake + args: + chdir: "{{ actual_home }}/tutorials/partitioned-heat-conduction/solver-openfoam" + executable: /bin/bash + environment: + FOAM_INST_DIR: /usr/lib/openfoam diff --git a/ansible/playbooks/install-paraview.yml b/ansible/playbooks/install-paraview.yml new file mode 100644 index 0000000..bb22313 --- /dev/null +++ b/ansible/playbooks/install-paraview.yml @@ -0,0 +1,12 @@ +--- +- name: Install ParaView without recommends + hosts: all + become: true + + tasks: + - name: Install ParaView without recommended packages + apt: + name: paraview + state: present + install_recommends: no + diff --git a/ansible/playbooks/install-precice.yml b/ansible/playbooks/install-precice.yml new file mode 100644 index 0000000..8e77955 --- /dev/null +++ b/ansible/playbooks/install-precice.yml @@ -0,0 +1,191 @@ +--- +- name: Install preCICE and related tutorials + hosts: all + become: true + vars: + user_home: "/home/vagrant" + precice_repo: "https://github.com/precice/precice.git" + tutorials_repo: "https://github.com/precice/tutorials.git" + fortran_module_repo: "https://github.com/precice/fortran-module.git" + python_bindings_repo: "https://github.com/precice/python-bindings.git" + precice_path: "{{ user_home }}/precice" + venv_path: "{{ user_home }}/python-venvs/pyprecice" + + tasks: + - name: Install preCICE build dependencies + apt: + name: + - cmake + - libeigen3-dev + - libxml2-dev + - libboost-all-dev + - petsc-dev + - python3-dev + - python3-numpy + state: present + update_cache: yes + + - name: Clone preCICE repo if not present + git: + repo: "{{ precice_repo }}" + dest: "{{ precice_path }}" + version: main + depth: 1 + update: yes + become: false + + - name: Build and package preCICE + become: false + shell: | + mkdir -p build && cd build + cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DPRECICE_RELEASE_WITH_DEBUG_LOG=ON -DBUILD_TESTING=OFF -Wno-dev .. + make -j $(nproc) + rm -fv ./*.deb && make package + sudo apt-get install -y ./libprecice*_*.deb + rm -rfv ./*.deb ./*.tar.gz _CPack_Packages + args: + chdir: "{{ precice_path }}" + executable: /bin/bash + + - name: Copy examples from /usr/share + copy: + remote_src: true + src: /usr/share/precice/examples/ + dest: "{{ precice_path }}-examples" + owner: vagrant + group: vagrant + mode: preserve + + - name: Build solverdummies (C, C++, Fortran) + shell: | + cd solverdummies + for d in c cpp fortran; do + cd $d && cmake . && make && cd .. + done + args: + chdir: "{{ precice_path }}-examples" + executable: /bin/bash + become: false + + - name: Clone and build fortran-module + git: + repo: "{{ fortran_module_repo }}" + dest: "{{ precice_path }}-examples/solverdummies/fortran-module" + depth: 1 + update: yes + become: false + + - name: Build fortran-module examples + shell: | + make + cd examples/solverdummy && make + args: + chdir: "{{ precice_path }}-examples/solverdummies/fortran-module" + executable: /bin/bash + become: false + + - name: Clone tutorials if not present + git: + repo: "{{ tutorials_repo }}" + dest: "{{ user_home }}/tutorials" + depth: 1 + update: yes + become: false + + - name: Ensure Desktop directory exists + file: + path: "{{ user_home }}/Desktop" + state: directory + mode: '0755' + become: false + + - name: Remove existing Desktop/tutorials if any + file: + path: "{{ user_home }}/Desktop/tutorials" + state: absent + become: false + + - name: Link tutorials to Desktop + file: + src: "{{ user_home }}/tutorials" + dest: "{{ user_home }}/Desktop/tutorials" + state: link + become: false + + - name: Build quickstart tutorial + shell: | + cmake . && make + args: + chdir: "{{ user_home }}/tutorials/quickstart/solid-cpp" + executable: /bin/bash + become: false + + - name: Vendor Rust dependencies for elastic-tube-1d + shell: | + mkdir -p .cargo && cargo vendor > .cargo/config.toml + args: + chdir: "{{ item }}" + executable: /bin/bash + loop: + - "{{ user_home }}/tutorials/elastic-tube-1d/solid-rust" + - "{{ user_home }}/tutorials/elastic-tube-1d/fluid-rust" + become: false + + - name: Run mesh download script for heat exchanger + shell: ./download-meshes.sh + args: + chdir: "{{ user_home }}/tutorials/heat-exchanger" + executable: /bin/bash + become: false + + - name: Install gnuplot + apt: + name: gnuplot + state: present + + - name: Install pip and venv + apt: + name: + - python3-pip + - python3-venv + state: present + + - name: Create Python venv for pyprecice + become: false + command: python3 -m venv {{ venv_path }} + args: + creates: "{{ venv_path }}/bin/activate" + + - name: Install pyprecice in venv + become: false + shell: | + source {{ venv_path }}/bin/activate + pip install --upgrade pip + pip install pyprecice + args: + executable: /bin/bash + + - name: Clone Python bindings repo and copy solverdummy + git: + repo: "{{ python_bindings_repo }}" + dest: "{{ user_home }}/python-bindings" + depth: 1 + update: yes + become: false + + - name: Copy python solverdummy example + copy: + src: "{{ user_home }}/python-bindings/examples/solverdummy" + dest: "{{ precice_path }}-examples/solverdummies/python" + remote_src: yes + owner: vagrant + group: vagrant + become: false + + - name: Remove python-bindings folder + file: + path: "{{ user_home }}/python-bindings" + state: absent + become: false diff --git a/ansible/playbooks/install-su2.yml b/ansible/playbooks/install-su2.yml new file mode 100644 index 0000000..047f4a2 --- /dev/null +++ b/ansible/playbooks/install-su2.yml @@ -0,0 +1,93 @@ +- name: Install SU2 and SU2-preCICE adapter + hosts: all + become: true + + vars: + su2_version: "7.5.1" + su2_tar: "v{{ su2_version }}.tar.gz" + su2_dir: "SU2-{{ su2_version }}" + su2_adapter_repo: "https://github.com/precice/su2-adapter.git" + + tasks: + - name: Create Python venv for SU2 adapter + ansible.builtin.shell: python3 -m venv ~/python-venvs/su2precice + args: + executable: /bin/bash + + - name: Activate venv and install pip dependencies + shell: | + source ~/python-venvs/su2precice/bin/activate + python -m pip install --upgrade pip + python -m pip install mpi4py setuptools + args: + executable: /bin/bash + + - name: Install swig + apt: + name: swig + state: present + + - name: Download SU2 {{ su2_version }} + get_url: + url: "https://github.com/su2code/SU2/archive/refs/tags/{{ su2_tar }}" + dest: "~/{{ su2_tar }}" + + - name: Extract SU2 + unarchive: + src: "~/{{ su2_tar }}" + dest: ~/ + remote_src: yes + + - name: Remove SU2 tarball + file: + path: "~/{{ su2_tar }}" + state: absent + + - name: Create ~/.su2-bashrc with SU2 environment variables + copy: + dest: ~/.su2-bashrc + content: | + export SU2_HOME="${HOME}/{{ su2_dir }}" + export SU2_RUN="${SU2_HOME}/SU2_CFD" + export PATH="${SU2_RUN}/bin/:${HOME}/su2-adapter/run/:${PATH}" + export PYTHONPATH="${SU2_RUN}/bin/:${PYTHONPATH}" + + - name: Source .su2-bashrc from .bashrc + lineinfile: + path: ~/.bashrc + line: ". ${HOME}/.su2-bashrc" + create: yes + + - name: Clone SU2 adapter + git: + repo: "{{ su2_adapter_repo }}" + dest: ~/su2-adapter + version: master + depth: 1 + + - name: Install SU2 adapter + shell: | + source ~/.su2-bashrc + ./su2AdapterInstall + args: + chdir: ~/su2-adapter + executable: /bin/bash + + - name: Fix missing header for Ubuntu 24.04 compatibility + lineinfile: + path: "~/{{ su2_dir }}/SU2_CFD/src/output/filewriter/CParaviewXMLFileWriter.cpp" + line: "#include " + insertafter: BOF + + - name: Configure and build SU2 with Python wrapper + shell: | + source ~/.su2-bashrc + ./meson.py build -Denable-pywrapper=true --prefix="${SU2_RUN}" && ./ninja -C build install + args: + chdir: "~/{{ su2_dir }}" + executable: /bin/bash + + - name: Remove libSU2Core.a to save space + file: + path: "~/{{ su2_dir }}/SU2_CFD/obj/libSU2Core.a" + state: absent diff --git a/ansible/playbooks/install-vscode.yml b/ansible/playbooks/install-vscode.yml new file mode 100644 index 0000000..38bb7c3 --- /dev/null +++ b/ansible/playbooks/install-vscode.yml @@ -0,0 +1,22 @@ +- name: Install Visual Studio Code and C++ extensions + hosts: all + become: true + + tasks: + - name: Install VS Code via snap + snap: + name: code + classic: true + state: present + + - name: Install C++ extension in VS Code + become: false + shell: code --install-extension ms-vscode.cpptools + args: + executable: /bin/bash + + - name: Install GNU Global extension in VS Code + become: false + shell: code --install-extension austin.code-gnu-global + args: + executable: /bin/bash