Running a Bash script in all salt-minions

921 views
Skip to first unread message

Bubunia Patra

unread,
Dec 15, 2017, 10:37:27 PM12/15/17
to Salt-users
Hi,

I am using CentOS -7 and it has latest Salt installed(salt 2017.7.2 (Nitrogen).  I want to execute a certain script in all the salt-minions connected from salt-master and provide me the exit status.
Below are the contents of init.sls contents. Can anyone help me in this regard please?

Regards
Pradeep

base:
  '*':
    - abcd


[root]$ vi abcd/init.sls
abcd.sh:
  cmd.run:
    - name: /root/scripts/run_test.sh
    - onlyif: test -f /root/scripts/run_test.sh
    - stateful: True


Error :

    ID: abcd
    Function: cmd.run
        Name: /root/scripts/run_test.sh
      Result: False
     Comment: /bin/sh: /root/scripts/run_test.sh: No such file or directory
     Started: 02:03:46.946724
    Duration: 12.701 ms
     Changes:

Then I tried jinja way after googling around a bit

 Rendering SLS 'base:abcd' failed: Problem running salt function in Jinja template: Unable to run command '['/root/scripts/test.sh']' with the context '{'timeout': None, 'with_communicate': True, 'shell': False, 'bg': False, 'stderr': -2, 'env': {'LANG': 'en_US.UTF-8', 'LC_NUMERIC': 'C', 'NOTIFY_SOCKET': '/run/systemd/notify', 'LC_MESSAGES': 'C', 'LC_IDENTIFICATION': 'C', 'LC_MONETARY': 'C', 'LC_COLLATE': 'C', 'LC_CTYPE': 'C', 'LC_ADDRESS': 'C', 'LC_MEASUREMENT': 'C', 'LC_TELEPHONE': 'C', 'LC_PAPER': 'C', 'LC_NAME': 'C', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin', 'LC_TIME': 'C'}, 'stdout': -1, 'close_fds': True, 'stdin': None, 'cwd': '/root'}', reason: command not found; line 1

---
{% set abcd = salt['cmd.run']('/root/scripts/test.sh') %}    <======================
/srv/salt/abcd/init.sls:
  file.managed:
    - source: {{ abcd }}
    - template: jinja
    - user: root
    - group: root
    - mode: 644






Dafydd Jones (techneg.it)

unread,
Dec 18, 2017, 11:28:50 AM12/18/17
to salt-...@googlegroups.com
You would want to use cmd.script if the script needs to be transferred to the minions prior to execution.

Dafydd

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/77d539db-3d63-4781-9bb7-3402374c9d63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages