Last active
September 18, 2019 21:43
-
-
Save optiz0r/47c2a233f23538d8ccc8b140ae293574 to your computer and use it in GitHub Desktop.
puppet_env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
metadata :name => "puppet_env", | |
:description => "Triggers updates of puppetserver environments using puppet-env-manager library", | |
:author => "Ben Roberts", | |
:license => "Apache-2.0", | |
:version => "0.1", | |
:url => "https://github.com/optiz0r/puppet-env-manager-agent", | |
:provider => "external", | |
:timeout => 900 | |
action "update_all", :description => "Updates all environments" do | |
display :always | |
input :force, | |
:prompt => "Force", | |
:description => "Forces update of modules even if no changes were detected (can be slow)", | |
:type => :boolean, | |
:optional => true | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://choria.io/schemas/mcorpc/ddl/v1/agent.json", | |
"metadata": { | |
"license": "Apache-2.0", | |
"author": "Ben Roberts", | |
"timeout": 900, | |
"name": "puppet_env", | |
"version": "0.1", | |
"url": "https://github.com/optiz0r/puppet-env-agent", | |
"description": "Triggers updates of puppetserver environments using puppet-env-manager library", | |
"provider": "external" | |
}, | |
"actions": [ | |
{ | |
"action": "update_all", | |
"input": { | |
"force": { | |
"prompt": "Force", | |
"description": "Forces update of modules even if no changes were detected (can be slow)", | |
"type": "boolean", | |
"default": false, | |
"optional": true, | |
"validation": "", | |
"maxlength": 0, | |
"list": null | |
} | |
}, | |
"output": {}, | |
"display": "always", | |
"description": "Updates all environments", | |
"aggregate": [] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import logging | |
import os | |
from distutils.spawn import find_executable | |
from mco_agent import Agent, action, dispatch, register_actions | |
from puppet_env_manager.config import EnvironmentManagerConfig | |
from puppet_env_manager.manager import EnvironmentManager | |
@register_actions | |
class PuppetEnv(Agent): | |
PATH = '/usr/bin:/usr/sbin:/bin:/sbin' | |
def should_activate(self): | |
pem_exe = find_executable('puppet-env-manager', os.environ.get('PATH', self.PATH)) | |
if pem_exe is None: | |
self.logger.error("Did not find puppet-env-manager, disabling") | |
return False | |
else: | |
self.logger.error("Found puppet-env-manager at {0}, enabling".format(pem_exe)) | |
return True | |
@action | |
def update_all(self): | |
""" Updates all puppet environments on a puppetserver | |
""" | |
logging.getLogger('puppet_env_manager').setLevel(self.logger.getEffectiveLevel()) | |
# Librarian requires some environment variables be set | |
os.environ.setdefault('HOME', '/root') | |
os.environ.setdefault('PATH', self.PATH) | |
force = self.request.data.get('force', False) | |
config_file = self.config.get('config_file', '/etc/puppet-env-manager/config.yaml') | |
self.logger.info("Loading PEM configuration") | |
pem_config = EnvironmentManagerConfig(path=config_file) | |
pem_config.load() | |
self.logger.info("Starting update_all") | |
manager = EnvironmentManager( | |
**pem_config.get_config() | |
) | |
manager.update_all_environments(force=force) | |
self.logger.info("Finished update_all") | |
if __name__ == '__main__': | |
dispatch(PuppetEnv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment