-
-
Notifications
You must be signed in to change notification settings - Fork 7
Convert provisioning shell scripts to reusable Ansible playbooks (#96) #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BytePaul
wants to merge
12
commits into
precice:develop
Choose a base branch
from
BytePaul:feature/ansible-provisioning
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
47ba29c
Add Ansible playbooks for reusable provisioning (#96)
BytePaul 0c130d0
Re-add Ansible playbooks as regular files
BytePaul 1d3de51
ADd GUI Installation
BytePaul bf23b84
CI added
BytePaul 822938e
Update README.md
BytePaul 79d686e
Update README.md
BytePaul d18bd9d
Merge branch 'feature/ansible-provisioning' of github.com:BytePaul/vm…
BytePaul d178fd7
Trigger CI
BytePaul 3effe14
Trigger CI
BytePaul ebe1827
Modified CI
BytePaul 59ab775
Basics: Add/edit comments, remove an unnecessary task
MakisH 5959ca6
Cleaup README.md
MakisH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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. | ||
|
|
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
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this, right?
Suggested change
|
||||||||
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
| 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 |
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
| 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 }}" |
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
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?