-
-
Save jalons/5207481 to your computer and use it in GitHub Desktop.
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
#!py | |
import pprint | |
import yaml | |
space_character = " " | |
def run(): | |
''' | |
Print the config files | |
''' | |
t = { | |
'salt-cloud': {'pkg': ['installed']}, | |
'/etc/salt/cloud': cloud_config(), | |
'/etc/salt/cloud.map': _yaml_templated('map'), | |
'/etc/salt/cloud.profiles': profiles_config(), | |
} | |
return t | |
def cloud_config(): | |
d = "" | |
config = pillar['clouds']['config'] | |
providers = config | |
for opt in config: | |
if opt == 'providers': | |
for provider_name, provider_opts in config[opt].items(): | |
for k, v in provider_opts.items(): | |
print "{provider}.{k}: {v}\n".format(provider=provider_name,k=k,v=v) | |
d += "{provider}.{k}: {v}\n".format(provider=provider_name,k=k,v=v) | |
else: | |
count = 0 | |
d += "%s%s:\n" % (space_character*count, opt) | |
d += _dict_to_yaml(config[opt], count+1) | |
d += "\n" | |
return _yaml_templated(data=d) | |
def profiles_config(): | |
d = "" | |
count = 0 | |
profiles = pillar['clouds']['profiles'] | |
for profile in profiles: | |
for name in profile: | |
d += "%s%s:\n" % (space_character*count, name) | |
d += _dict_to_yaml(profile[name], count+1) | |
return _yaml_templated(data=d) | |
def _recursive_yaml(m): | |
d = "" | |
count = 0 | |
profiles = pillar['clouds'][m] | |
for profile in profiles: | |
for name in profile: | |
d += "%s%s:\n" % (space_character*count, name) | |
d += _dict_to_yaml(profile[name], count+1) | |
return _yaml_templated(data=d) | |
def _dict_to_yaml(d, count=0): | |
str = "" | |
for k in d: | |
v = d[k] | |
if isinstance(v, dict): | |
str += "%s%s:\n" % (space_character*count, k) | |
str += _dict_to_yaml(v, count + 1) | |
str += "\n" | |
else: | |
str += "{whitespace}{key}: {value}\n".format(whitespace=space_character*count,key=k, value=v) | |
return str | |
def _yaml_templated(m=None,data=None): | |
if not data: | |
data = yaml.dump(pillar['clouds'][m]) | |
return { | |
'file.managed': [ | |
{'source': 'salt://salt/cloud/templates/yaml'}, | |
{'template': 'jinja'}, | |
{'mode', '644'}, | |
{'context': { | |
'data': data | |
}} | |
] | |
} | |
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
clouds: | |
config: | |
providers: | |
JOYENT: | |
user: USER | |
password: PASSWORD | |
profiles: | |
- master: | |
provider: joyent | |
image: ubuntu-12.04 | |
size: Medium 2GB | |
script: Ubuntu | |
minion: | |
role: master | |
map: | |
db: | |
minion: | |
minion: | |
log_level: debug | |
grains: | |
role: db | |
app: | |
minion: | |
grains: | |
role: app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment