Created
May 24, 2018 07:35
-
-
Save href/751b92e1c5448ed1cc7f201e9a3de8f4 to your computer and use it in GitHub Desktop.
Example of our internal use of Suitable
This file contains hidden or 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
import click | |
from suitable import Api | |
from textwrap import dedent | |
@click.command() | |
@click.argument('hostname') | |
def upgrade_puppet(hostname): | |
""" Upgrades a puppet client from puppet 3.8 to 4.x. """ | |
api = Api(hostname, sudo=True) | |
assert "puppetmaster" not in hostname, """ | |
Do not run this script against a puppetmaster | |
""" | |
facts = api.setup().ansible_facts() | |
if hostname.endswith('.dev'): | |
environment = 'testing' | |
else: | |
environment = 'production' | |
config = dedent(f"""\ | |
[main] | |
certname = "{hostname.replace('.dev', '.org')}" | |
environment = {environment} | |
server = "puppetmaster.example.org" | |
""") | |
if facts['ansible_os_family'] == 'FreeBSD': | |
upgrade_freebsd(api, config) | |
else: | |
upgrade_ubuntu(api, facts['ansible_lsb']['codename'], config) | |
def upgrade_ubuntu(api, codename, config): | |
root = { | |
'owner': 'root', | |
'group': 'root', | |
'mode': '0644' | |
} | |
api.copy( | |
dest='/etc/apt/sources.list.d/puppet.list', | |
content=f'deb http://apt.puppetlabs.com/ {codename} PC1', | |
**root | |
) | |
api.apt(name='puppet', state='absent') | |
api.apt(name='puppet-agent', state='present', update_cache='yes') | |
api.copy( | |
dest='/etc/puppetlabs/puppet/puppet.conf', | |
content=config, | |
**root | |
) | |
def upgrade_freebsd(api, config): | |
root = { | |
'owner': 'root', | |
'group': 'wheel', | |
'mode': '0644' | |
} | |
api.pkgng(name='puppet38', state='absent') | |
api.pkgng(name='puppet4', state='present') | |
api.copy( | |
dest='/usr/local/etc/puppet/puppet.conf', | |
content=config, | |
**root | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment