Parse arguments for install script from ansible

This commit is contained in:
Yosafat Marselino 2025-05-17 10:00:15 -04:00
parent 0258791331
commit 6076e31518
2 changed files with 11 additions and 2 deletions

View File

@ -3,6 +3,14 @@
hosts: target_hosts hosts: target_hosts
become: yes # Use sudo if needed become: yes # Use sudo if needed
tasks: tasks:
- name: Convert params dictionary to command line arguments
set_fact:
cli_args: "{{ script_params | dict2items | map('format', '--{key} {value}') | join(' ') }}"
- name: Show arguments to be used
debug:
var: cli_args
- name: Create temporary directory for scripts - name: Create temporary directory for scripts
file: file:
path: /tmp/downloaded_scripts path: /tmp/downloaded_scripts
@ -29,7 +37,8 @@
- { name: 'script1.sh' } - { name: 'script1.sh' }
- name: Execute downloaded scripts - name: Execute downloaded scripts
shell: "/tmp/downloaded_scripts/{{ item.item.name }} --ip 192.168.8.54 --prune true " #shell: "/tmp/downloaded_scripts/{{ item.item.name }} --ip 192.168.8.54 --prune true "
shell: "/tmp/downloaded_scripts/{{ item.item.name }} {{ cli_args }} "
loop: "{{ downloaded_scripts.results }}" loop: "{{ downloaded_scripts.results }}"
register: script_output register: script_output

View File

@ -95,7 +95,7 @@ check_existing_cluster() {
if command_exists kubectl && kubectl cluster-info &>/dev/null; then if command_exists kubectl && kubectl cluster-info &>/dev/null; then
echo "Found existing installation" echo "Found existing installation"
echo "Proceed to clean em UP" echo "Proceed to clean em UP"
if [[ $PRUNE != false ]]; then if [[ $PRUNE != true ]]; then
echo "Kubernetes cluster removal skipped. Exiting script." echo "Kubernetes cluster removal skipped. Exiting script."
exit 0 exit 0
fi fi