Skip to content
68 changes: 68 additions & 0 deletions ansible/README.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the way to run everything?
Should we define hosts that execute different playbooks?
Should we use import?

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Ansible Playbooks for preCICE Development Environment Setup
This repository contains a set of Ansible playbooks that automate the provisioning of the preCICE development environment. These playbooks are converted from original `.sh` shell scripts, making the setup process modular, idempotent, and more maintainable.
## 📁 Directory Structure

ansible/
├── inventory.ini # Target hosts configuration
├── playbooks/ # Individual provisioning playbooks
│ ├── install-basics.yml
│ ├── install-aste.yml
│ ├── install-calculix.yml
│ ├── install-code_aster.yml
│ ├── install-config-visualizer.yml
│ ├── install-dealii.yml
│ ├── install-devel.yml
│ ├── install-dune.yml
│ ├── install-fenics.yml
│ ├── install-fmiprecice.yml
│ ├── install-julia-bindings.yml
│ ├── install-micro-manager.yml
│ ├── install-openfoam.yml
│ ├── install-paraview.yml
│ ├── install-precice.yml
│ ├── install-su2.yml
│ └── install-vscode.yml
└── README.md # This file

## ✅ Purpose
These playbooks set up all necessary software components and development tools for contributing to or working with preCICE, a coupling library for partitioned multi-physics simulations.
The playbooks were translated from original shell scripts to:
- Ensure idempotency (safe to re-run)
- Improve clarity and maintainability
- Allow easier customization and reuse
- Support inventory-based execution (local or remote hosts)
## 🛠️ Conversion: Shell Script → Ansible Playbook

| Shell Script Action | Ansible Equivalent |
|--------------------------------|--------------------------------|
| apt-get update/install | apt module with update_cache |
| adduser, usermod | user and group modules |
| chmod +x / mkdir -p | file module with mode/path |
| curl or wget scripts | get_url or uri module |
| bash install.sh | script or command module |
| systemctl enable/start | systemd module |

## 🚀 Usage
### 1. Clone the repository
git clone https://github.com/<your-username>/ansible.git
cd ansible
### 2. Update inventory
[local]
localhost ansible_connection=local
### 3. Run a playbook
ansible-playbook -i inventory.ini playbooks/install-precice.yml
## 🔍 Testing & Validation
- All playbooks tested on Ubuntu 22.04 using Vagrant VM
- Playbooks support `--check` mode for dry-run testing
ansible-playbook -i inventory.ini playbooks/install-precice.yml --check --diff
- Playbooks can be extended with tags and variables
## 📌 Notes
- These playbooks do not use Ansible roles yet, but future restructuring may modularize common logic (e.g., user setup, package installation)
- Ensure Python and `sudo` are available on the target machines
## 📈 Next Steps
- Add Molecule-based testing
- Introduce group_vars for better parameterization
- Modularize with Ansible roles (e.g., docker, precice, visualization)
## 🤝 Contributing
Pull requests and suggestions are welcome! If you have a shell script you’d like converted into an Ansible playbook, open an issue or contribute directly.

5 changes: 5 additions & 0 deletions ansible/inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[local]
localhost ansible_connection=local

[remote]
# Example: server1 ansible_host=192.168.1.100 ansible_user=youruser
Comment on lines +3 to +5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this, right?

Suggested change
[remote]
# Example: server1 ansible_host=192.168.1.100 ansible_user=youruser

70 changes: 70 additions & 0 deletions ansible/playbooks/install-aste.yml
Original file line number Diff line number Diff line change
@@ -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
97 changes: 97 additions & 0 deletions ansible/playbooks/install-basics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
- name: Install GUI, development tools, and setup VM environment
hosts: all
become: true

vars:
keyboard_layout: us
hostname: precicevm
desktop_shortcut: /usr/share/applications/xfce-keyboard-settings.desktop

pre_tasks:
- name: Remove bad APT retry config if present
file:
path: /etc/apt/apt.conf.d/80-retries
state: absent

- name: Set correct APT retry config
copy:
dest: /etc/apt/apt.conf.d/80-retries
content: |
Acquire::Retries "4";
force: yes

tasks:
- 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: dist
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 development tools
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 US keyboard layout
lineinfile:
path: /etc/default/keyboard
regexp: '^XKBLAYOUT='
line: 'XKBLAYOUT="{{ keyboard_layout }}"'

- name: Copy keyboard settings shortcut to Desktop
copy:
src: "{{ desktop_shortcut }}"
dest: "{{ ansible_env.HOME }}/Desktop/"
remote_src: yes
mode: '0755'

- name: Set hostname
hostname:
name: "{{ hostname }}"
65 changes: 65 additions & 0 deletions ansible/playbooks/install-calculix.yml
Original file line number Diff line number Diff line change
@@ -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
Loading