Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2015 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/040a998d6c371d9ceb4c to your computer and use it in GitHub Desktop.
Save anonymous/040a998d6c371d9ceb4c to your computer and use it in GitHub Desktop.
[root@head0a salt]# cat _states/torque.py
# -*- coding: utf-8 -*-
'''
Scyld Service Management
========================
Ensure Torque's pbs_mom is installed and running.
.. code-block:: yaml
torque:
torque.installed:
- package: /opt/wsu/torque/torque-package-mom-linux-x86_64.sh
- check_file: /usr/local/sbin/pbs_mom
'''
def installed(package, check_file):
'''
Installs the named Torque package if the file given in check_file does not exist.
package
The Torque package (script, not RPM) to install.
check_file
The file to check to see if the package is already installed.
'''
ret = {'name' : name.
'package': package,
'check_file': check_file,
'changes': {},
'result': False,
'comment': 'test'}
import os
import re
import subprocess
if os.path.exists(check_file):
ret['comment'] = "Check file exists, Torque package already installed."
ret['result'] = True
else:
installer_proc = subprocess.Popen([package], stdin=None, shell=False)
status = installer_proc.wait()
if status == 0:
ret['comment'] = "Installed Torque package."
ret['result'] = True
ret['changes']["Torque package"] = {}
ret['changes']["Torque package"]["old"] = "Package " + package + " not installed (check file " + check_file + " not found)"
ret['changes']["Torque package"]["new"] = "Package " + package + " successfully installed"
else:
ret['comment'] = "Failed to install Torque package."
ret['result'] = False
ret['changes']["Torque package"] = {}
ret['changes']["Torque package"]["old"] = "Package " + package + " not installed (check file " + check_file + " not found)"
ret['changes']["Torque package"]["new"] = "Package " + package + " installer ran and failed with status " + str(status)
return ret
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]# cat pbs_mom.sls
pbs_mom:
torque.installed:
- package: /opt/wsu/torque/torque-package-mom-linux-x86_64.sh
- check_file: /usr/local/sbin/pbs_mom
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]# salt compute0-stateless.test.example.edu saltutil.sync_states
compute0-stateless.test.example.edu:
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]#
[root@head0a salt]# salt compute0-stateless.test.example.edu state.sls pbs_mom
compute0-stateless.test.example.edu:
The minion function caused an exception: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/minion.py", line 1173, in _thread_return
return_data = func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/modules/state.py", line 708, in sls
ret = st_.state.call_high(high_)
File "/usr/lib/python2.7/site-packages/salt/state.py", line 2068, in call_high
ret = dict(list(disabled.items()) + list(self.call_chunks(chunks).items()))
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1624, in call_chunks
running = self.call_chunk(low, running, chunks)
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1770, in call_chunk
self._mod_init(low)
File "/usr/lib/python2.7/site-packages/salt/state.py", line 613, in _mod_init
self.states['{0}.{1}'.format(low['state'], low['fun'])] # pylint: disable=W0106
File "/usr/lib/python2.7/site-packages/salt/utils/lazy.py", line 90, in __getitem__
raise KeyError(key)
KeyError: 'torque.installed'
[root@head0a salt]#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment