59 lines
1.8 KiB
YAML
59 lines
1.8 KiB
YAML
---
|
|
- name: Curl and execute scripts on target machine
|
|
hosts: target_hosts
|
|
become: yes # Use sudo if needed
|
|
vars:
|
|
script_params:
|
|
ip: "192.168.1.100"
|
|
prune: "false"
|
|
tasks:
|
|
- name: Convert params dictionary to command line arguments
|
|
set_fact:
|
|
cli_args: "{% for key, value in script_params.items() %}--{{ key }} {{ value }} {% endfor %}"
|
|
|
|
- name: Show arguments to be used
|
|
debug:
|
|
var: cli_args
|
|
|
|
- name: Create temporary directory for scripts
|
|
file:
|
|
path: /tmp/downloaded_scripts
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Remove Old Scripts
|
|
shell: "rm /tmp/downloaded_scripts/* || true"
|
|
|
|
- name: Download scripts using curl
|
|
command: >
|
|
curl "{{ item.url }}" -o "/tmp/downloaded_scripts/{{ item.name }}"
|
|
args:
|
|
creates: "/tmp/downloaded_scripts/{{ item.name }}"
|
|
loop:
|
|
- { name: 'script1.sh', url: 'https://git.nnag.me/infidel/jenkins-smo-autodeployment/raw/branch/master/test-scripts/install_k8s.sh' }
|
|
register: downloaded_scripts
|
|
|
|
- name: Make downloaded scripts executable
|
|
file:
|
|
path: "/tmp/downloaded_scripts/{{ item.name }}"
|
|
mode: '0755'
|
|
loop:
|
|
- { name: 'script1.sh' }
|
|
|
|
- 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 }} {{ cli_args }} "
|
|
loop: "{{ downloaded_scripts.results }}"
|
|
register: script_output
|
|
|
|
- name: Display script execution results
|
|
debug:
|
|
msg: "{{ item.stdout_lines }}"
|
|
loop: "{{ script_output.results }}"
|
|
|
|
- name: Clean up temporary directory
|
|
file:
|
|
path: /tmp/downloaded_scripts
|
|
state: absent
|
|
when: cleanup_after | default(true)
|