Question: how to Use name of shell script as value to variable and execute it

10 views
Skip to first unread message

Adam Memon

unread,
May 29, 2020, 6:31:46 AM5/29/20
to Ansible Project
Hi All,

I have a requirement to login to multiple application servers and just run different scripts individually on different servers
Rather than creating task for each server - I would like to just create one task with name of the shell script in a variable

How can we implement this

Eg :
====inventory file===
[APP]
host1.example.com path=/home/app script=start.sh
host2.example.com path=/home/app2 script=echo y | start_app.sh


===YAML file===
---
- hosts: APP
  remote_user: app
  tasks:
  - name: START APP
    shell: |
           cd "{{ path }}"
           "{{ script }}"
    register: result
    tags: check
  - debug: msg="{{ result.stdout }}"


Reply all
Reply to author
Forward
0 new messages