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