Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of our internal use of Suitable
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
You can’t perform that action at this time.