1
|
|
|
#!/usr/bin/env python |
2
|
|
|
|
3
|
|
|
import argparse |
4
|
|
|
|
5
|
|
|
from lib.remote_actions import PuppetBaseAction |
6
|
|
|
|
7
|
|
|
__all__ = [ |
8
|
|
|
'PuppetRunAgentAction' |
9
|
|
|
] |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class PuppetRunAgentAction(PuppetBaseAction): |
13
|
|
|
def run(self, server=None, certname=None, environment=None, |
14
|
|
|
daemonize=False, onetime=True, debug=None): |
15
|
|
|
args = ['agent'] |
16
|
|
|
|
17
|
|
|
if server: |
18
|
|
|
args += ['--server=%s' % (server)] |
19
|
|
|
|
20
|
|
|
if certname: |
21
|
|
|
args += ['--certname=%s' % (certname)] |
22
|
|
|
|
23
|
|
|
if environment: |
24
|
|
|
args += ['--environment=%s' % (environment)] |
25
|
|
|
|
26
|
|
|
if daemonize: |
27
|
|
|
args += ['--daemonize'] |
28
|
|
|
else: |
29
|
|
|
args += ['--no-daemonize'] |
30
|
|
|
|
31
|
|
|
if onetime: |
32
|
|
|
args += ['--onetime'] |
33
|
|
|
|
34
|
|
|
if debug: |
35
|
|
|
args += ['--debug'] |
36
|
|
|
|
37
|
|
|
cmd = self._get_full_command(args=args) |
38
|
|
|
self._run_command(cmd=cmd) |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
if __name__ == '__main__': |
42
|
|
|
parser = argparse.ArgumentParser(description='Run puppet agent') |
43
|
|
|
parser.add_argument('--server', help='Name of the puppet master server', |
44
|
|
|
required=False) |
45
|
|
|
parser.add_argument('--certname', help='Certname (unique ID) of the client', |
46
|
|
|
required=False) |
47
|
|
|
parser.add_argument('--environment', help='Environment to use in puppet run'), |
48
|
|
|
parser.add_argument('--daemonize', help='Send the process into the background', |
49
|
|
|
action='store_true', default=False, required=False) |
50
|
|
|
parser.add_argument('--onetime', help='Use one time run mode', |
51
|
|
|
action='store_true', default=True, required=False) |
52
|
|
|
parser.add_argument('--debug', help='Enable full debugging', |
53
|
|
|
action='store_true', default=False, required=False) |
54
|
|
|
args = vars(parser.parse_args()) |
55
|
|
|
|
56
|
|
|
if not args['daemonize'] and not args['onetime']: |
57
|
|
|
raise ValueError('When --no_onetime is provided, --daemonize needs' |
58
|
|
|
' to be provided as well') |
59
|
|
|
|
60
|
|
|
action = PuppetRunAgentAction() |
61
|
|
|
action.run(**args) |
62
|
|
|
|