-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
file { "${settings::confdir}/csr_attributes.yaml": | ||
ensure => 'file', | ||
mode => '0640', | ||
group => 'puppet', | ||
content => '@{content}' | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
augeas { 'puppet.conf': | ||
context => "/files${settings::confdir}/puppet.conf", | ||
changes => [ | ||
@{settings} | ||
], | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import collections | ||
|
||
from six import iteritems | ||
from typing import Sequence, Tuple | ||
|
||
from puppeter.container import Named | ||
from puppeter.domain.model.configurer import Configurer, ScriptFormat | ||
from puppeter.domain.model.installer import PuppetConf | ||
from puppeter.domain.model.ordered import Order | ||
|
||
|
||
@Named('puppet.conf') | ||
@Order(900) | ||
class PuppetConfConfigurer(Configurer): | ||
|
||
def __init__(self, installer): | ||
self.__puppetconf = installer.puppetconf() # type: PuppetConf | ||
|
||
def produce_commands(self): | ||
# type: () -> Sequence[str] | ||
collector = self._collector() | ||
augeas = self.__puppetconf_as_augeas() | ||
augeas_pp = ',\n '.join(list(map(lambda cmd: '"{cmd}"'.format(cmd=cmd), augeas))) | ||
collector.collect_from_template( | ||
description="Configuring Puppet configuration file (puppet.conf)", | ||
format=ScriptFormat.PUPPET, | ||
template='puppetconf.pp', | ||
mapping={ | ||
'settings': augeas_pp | ||
} | ||
) | ||
return collector.lines() | ||
|
||
def __puppetconf_as_augeas(self): | ||
# type: () -> Sequence[str] | ||
flat = self.__flatten(self.__puppetconf) | ||
return list(map(PuppetConfConfigurer.__augeaize, iteritems(flat))) | ||
|
||
@staticmethod | ||
def __augeaize(tup): | ||
# type: (Tuple[str, str]) -> str | ||
key, value = tup | ||
try: | ||
safe = { | ||
str: lambda x: "'{str}'".format(str=x), | ||
bool: lambda x: 'true' if x else 'false', | ||
}[value.__class__](value) | ||
except KeyError: | ||
safe = value | ||
return "set {key} {value}".format(key=key, value=safe) | ||
|
||
@staticmethod | ||
def __flatten(d, parent_key='', sep='/'): | ||
items = [] | ||
for k, v in iteritems(d): | ||
new_key = parent_key + sep + k if parent_key else k | ||
if isinstance(v, collections.MutableMapping): | ||
items.extend(PuppetConfConfigurer.__flatten(v, new_key, sep=sep).items()) | ||
else: | ||
items.append((new_key, v)) | ||
return dict(items) |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def merge(*dict_args): | ||
""" | ||
Given any number of dicts, shallow copy and merge into a new dict, | ||
precedence goes to key value pairs in latter dicts. | ||
""" | ||
result = {} | ||
for dictionary in dict_args: | ||
result.update(dictionary) | ||
return result |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fqdn: front-01.acme.internal | ||
installer: | ||
mode: Agent | ||
type: pc4x | ||
puppet.conf: | ||
main: | ||
server: puppet.acme.internal | ||
timesync: | ||
type: ntpd | ||
servers: | ||
- ts1.acme.internal | ||
- ts2.acme.internal | ||
- ts3.acme.internal | ||
- ts4.acme.internal | ||
csr-attributes: | ||
pp_project: acme | ||
pp_role: frontend | ||
pp_zone: app | ||
pp_environment: stage | ||
pp_datacenter: dc2 | ||
pp_region: public | ||
|
||
|
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from puppeter.domain.model import Collection4xInstaller | ||
from puppeter.persistence.service import PuppetConfConfigurer | ||
|
||
|
||
def test_puppetconf(): | ||
# given | ||
installer = Collection4xInstaller() | ||
installer.read_raw_options({ | ||
'mode': 'Agent', | ||
'puppet.conf': { | ||
'main': { | ||
'server': 'puppet.acme.internal' | ||
}, | ||
'agent': { | ||
'noop': True | ||
} | ||
} | ||
}) | ||
configurer = PuppetConfConfigurer(installer) | ||
|
||
# when | ||
commands = configurer.produce_commands() | ||
|
||
# then | ||
assert configurer.bean_name() == 'puppet.conf' | ||
assert configurer.order() == 900 | ||
assert found("set main/server 'puppet.acme.internal'").inside(commands) | ||
assert found("set agent/noop true").inside(commands) | ||
|
||
|
||
def found(st): | ||
class Found: | ||
def __init__(self): | ||
pass | ||
|
||
@staticmethod | ||
def inside(lst): | ||
return any(st in s for s in lst) | ||
return Found |
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