-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: develop
Are you sure you want to change the base?
Conversation
MakisH
left a comment
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.
This PR does not add the files themselves, but only an unresolved pointer to a submodule. There is no content to review/test here at the moment.
I also see that this PR is highly likely generated by an LLM. I would appreciate more an original description (with its expected flaws), including your viewpoint and your concerns and suggestions.
In case the playbooks are also generated by an LLM, this should be clearly stated. I am aware that ChatGPT can convert these, but what we need here is also ownership of the contribution: we need that someone has actually validated the concept and tested the system. I do not have enough evidence to feel confident of that at the moment.
Please revise.
|
Hi @MakisH, I have created and ran the playbook on the virtual machine; hence, they have been created and validated by me. In the updated version of PR comment, I have tried to be descriptive of the issues I faced while running it on the VM. Also, I have fixed the accidental submodule pointer and ensured the Ansible playbooks for viewing. Even though the initial description has been LLM generated the idea behind the comments are mine and I made use of the LLM to polish things up. Thank you for the feedback. |
|
Thank you for the updates, @BytePaul, I can now see the changes, but I need some time to review and test everything.
Does this mean that install-code_aster.yml also works? I would expect not, but I don't see it under the list of issues. |
|
It just means I tried running to the best possible outcome possible so far. And the results have been documents and discussed in the PR |
| src: /usr/share/precice/examples/ | ||
| dest: "{{ precice_path }}-examples" |
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.
This playbook currently fails at this point. The original is:
sudo apt-get install -y ./libprecice*_*.deb
...
cp -r /usr/share/precice/examples/ ./precice-examples
It looks like the src and dest are swapped here.
… into feature/ansible-provisioning
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Lint Ansible Playbooks 🧹 | ||
| uses: docker://ansible/ansible-lint:latest |
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.
This image does not seem to exist on the public Docker Hub registry: https://hub.docker.com/search?q=ansible-lint Where is that recommended? Is there a common alternative?
This is the reason that the CI is currently failing.
|
|
||
| [remote] | ||
| # Example: server1 ansible_host=192.168.1.100 ansible_user=youruser |
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.
We don't need this, right?
| [remote] | |
| # Example: server1 ansible_host=192.168.1.100 ansible_user=youruser |
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?
Convert provisioning shell scripts to reusable Ansible playbooks (#96)
Summary
This pull request addresses Issue #96: Reusable provisioning by converting selected shell-based provisioning scripts into reusable, idempotent Ansible playbooks. The goal is to support reproducible and flexible provisioning across Vagrant VMs, Live USB environments (Cubic), and Apptainer containers, using a common YAML-based infrastructure.
✔️ Converted Scripts
The following shell scripts were translated into Ansible playbooks:
install-aste.shinstall-aste.ymlinstall-basics.shinstall-basics.ymlinstall-calculix.shinstall-calculix.ymlinstall-code_aster.shinstall-code_aster.ymlinstall-config-visualizer.shinstall-config-visualizer.ymlinstall-dealii.shinstall-dealii.ymlinstall-devel.shinstall-devel.ymlinstall-dune.shinstall-dune.ymlinstall-fenics.shinstall-fenics.ymlinstall-fmiprecice.shinstall-fmiprecice.ymlinstall-julia-bindings.shinstall-julia-bindings.ymlinstall-micro-manager.shinstall-micro-manager.ymlinstall-openfoam.shinstall-openfoam.ymlinstall-paraview.shinstall-paraview.ymlinstall-precice.shinstall-precice.ymlinstall-su2.shinstall-su2.ymlinstall-vscode.shinstall-vscode.yml🔧 Structure
inventory.ini: for host targeting (currently local via Vagrant)README.md: describes usage, structure, and future goals💡 Improvements Over Shell Scripts
🧪 Testing
--checkand--diffmodes✅ Issues and Fixes
Issue 1:
/rootpath inaccessibleFile: All playbooks
Fix: Used
{{ lookup('env', 'HOME') }}to dynamically get the current user’s home directory.Issue 2: Permission denied when creating
/root/python-venvsFile:
install-fenics.yml,install-julia-bindings.ymlFix: Used
become: falsefor tasks that create or access user-level directories such as virtual environments.Issue 3: Attempt to write to
/root/.bashrcFile:
install-openfoam.ymlFix: Ensured
.bashrcmodifications target the correct non-root user’s home directory using{{ user_home }}/.bashrc.Issue 4:
install-dune.ymltried writing to/root/dune-dumuxFile:
install-dune.ymlFix: Used user-local directory based on
{{ user_home }}and ensured properbecomesettings.Issue 5:
install-fenics.ymlfailed on virtualenv creationFile:
install-fenics.ymlFix: Corrected permissions by ensuring virtual environment creation uses
become: falseand the rightuser_home.Issue 6:
install-julia-bindings.ymlfailed at/root/python-venvsFile:
install-julia-bindings.ymlFix: Fixed path using dynamic home directory and ran venv and pip commands without
become.Issue 7:
install-openfoam.ymlfailed due to the wrong tutorial directoryFile:
install-openfoam.ymlFix: Updated tutorial path using
{{ user_home }}/tutorials/...instead of~/...or/root/....Issue 8:
.bashrcnot writable by current userFile:
install-openfoam.yml,install-aste.ymlFix: Ensured tasks modifying
.bashrcrun withoutbecomeand use the actual user’s home directory.Issue 9:
.bashrcedit failed silently under root contextFile:
install-aste.ymlFix: Used
lineinfilemodule with correct user path andbecome: false.Issue 10:
install-code_aster.ymlhas unresolved issues with installationFile:
install-code_aster.ymlFix: No Fix Yet.
Suggestions and Concerns for Ansible Playbook Refactoring
1. Use
become: falsefor User-Space ActionsConcern: Tasks like creating virtual environments or modifying user
.bashrcshould run under the actual user context, not root.Suggestion: Always explicitly set
become: falsefor such tasks to avoid permission errors or modifications to/root.2. Ensure Directories Exist Before Writing
Concern: Tasks that write to paths like
~/python-venvs/foocan fail if the base directory doesn't exist.Suggestion: Add
filetasks to ensure directories exist with correct ownership before accessing them.3. Avoid Appending Duplicate Lines to
.bashrcConcern: Repeated playbook runs can duplicate
exportlines in.bashrc.Suggestion: Use
regexpwithlineinfileto match and replace lines safely instead of blindly appending withinsertafter: EOF.4. Use
chdirfor Directory ChangesConcern: Inline
cdcommands inshellcan fail silently or be harder to debug.Suggestion: Use Ansible's
chdirparameter to set working directories cleanly forshellorcommandtasks.5. Consistent Use of
user_homeVariableConcern: Hardcoding paths like
/home/vagrantreduces portability.Suggestion: Use
lookup('env', 'HOME')oransible_env.HOMEas a variable (user_home) across playbooks for user-path operations.6. Use
creates:for Idempotency in Virtualenv CreationConcern: Without
creates:, a playbook may recreate or overwrite existing environments.Suggestion: Use
creates: "{{ path }}/bin/activate"to make tasks idempotent.7. Avoid Running User Shell Configurations as Root
Concern: Tasks that append to
.bashrcor clone to~/may default to/root/ifbecome: trueis active.Suggestion: Use
become: falsewhen working on user-specific files like.bashrc, Python virtual environments, or home directories.8. Ensure Correct Permissions When Mixing
become: trueandfalseConcern: Switching between elevated and non-elevated contexts can cause permission conflicts.
Suggestion: Always check ownership and permissions, especially when files are created with
become: trueand accessed without it later.Closes #96