Example #1
0
from pyinfra import host
from pyinfra.operations import apt, server, yum

SUDO = True

if host.fact.linux_name in ['CentOS', 'RedHat']:
    yum.packages(
        {'Install some packages'},
        ['cronie'],
        update=True,
    )

if host.fact.linux_name in ['Ubuntu']:
    apt.packages(
        {'Install some packages'},
        ['cron'],
        update=True,
    )

# simple example for a crontab
server.crontab(
    {'Backup /etc weekly'},
    '/bin/tar cf /tmp/etc_bup.tar /etc',
    name='backup_etc',
    day_of_week=0,
    hour=1,
    minute=0,
)

server.group(
    {'Create docker group'},
Example #2
0
if host in masters:
    server.hostname(
        name='Set the hostname for the Puppet Master',
        hostname='master.example.com',
    )

if host in agents:
    server.hostname(
        name='Set the hostname for an agent',
        hostname='agent.example.com',
    )

if host.fact.linux_name in ['CentOS', 'RedHat']:

    yum.packages(
        name='Install chrony for Network Time Protocol (NTP)',
        packages=['chrony'],
    )

    major = host.fact.linux_distribution['major']
    yum.rpm(
        name='Install Puppet Repo',
        src='https://yum.puppet.com/puppet6-release-el-{}.noarch.rpm'.format(
            major),
    )

    files.line(
        name='Ensure SELINUX is disabled',
        path='/etc/sysconfig/selinux',
        line=r'SELINUX=.*',
        replace='SELINUX=disabled',
    )
Example #3
0
        name='Install packages for python virtual environments',
        packages=[
            'gcc',
            'libffi-dev',
            'make',
            'musl-dev',
            'openssl-dev',
            'py3-pynacl',
            'py3-virtualenv',
            'python3-dev',
        ],
    )

if host.fact.linux_name in ['CentOS']:
    yum.packages(
        name='Install pip3 so you can install virtualenv',
        packages='python3-pip',
    )

if host.fact.linux_name in ['Ubuntu']:
    apt.packages(
        name='Install pip3 so you can install virtualenv',
        packages='python3-pip',
        update=True,
    )

if not host.fact.file('/usr/bin/pip'):
    files.link(
        name='Create link /usr/bin/pip that points to /usr/bin/pip3',
        path='/usr/bin/pip',
        target='/usr/bin/pip3',
    )
Example #4
0
        packages=[
            "gcc",
            "g++",
            "libffi-dev",
            "make",
            "musl-dev",
            "openssl-dev",
            "py3-pynacl",
            "py3-virtualenv",
            "python3-dev",
        ],
    )

if host.get_fact(LinuxName) in ["CentOS"]:
    yum.packages(
        name="Install pip3 so you can install virtualenv",
        packages=["python3-pip", "python3-devel", "gcc-c++", "make"],
    )

if host.get_fact(LinuxName) in ["Ubuntu"]:
    apt.packages(
        name="Install pip3 so you can install virtualenv",
        packages="python3-pip",
        update=True,
    )

if not host.get_fact(File, path="/usr/bin/pip"):
    files.link(
        name="Create link /usr/bin/pip that points to /usr/bin/pip3",
        path="/usr/bin/pip",
        target="/usr/bin/pip3",
    )
Example #5
0
from pyinfra import host
from pyinfra.operations import apt, server, yum

SUDO = True

if host.fact.linux_name in ['CentOS', 'RedHat']:
    yum.packages(
        name='Install some packages',
        packages=['cronie'],
        update=True,
    )

if host.fact.linux_name in ['Ubuntu']:
    apt.packages(
        name='Install some packages',
        packages=['cron'],
        update=True,
    )

# simple example for a crontab
server.crontab(
    name='Backup /etc weekly',
    command='/bin/tar cf /tmp/etc_bup.tar /etc',
    cron_name='backup_etc',
    day_of_week=0,
    hour=1,
    minute=0,
)

server.group(
    name='Create docker group',
Example #6
0
from pyinfra import host
from pyinfra.operations import yum

SUDO = True

# Note: This "if" below is not really required.
# For instance, if you run this deploy on an
# Ubuntu instance (which does not use yum)
# the yum.packages() will simply be skipped
if host.fact.linux_name in ['CentOS', 'RedHat']:

    yum.packages(
        name='Install some packages',
        packages=['vim-enhanced', 'vim', 'wget'],
        update=True,
    )

linux_id = host.fact.linux_distribution['release_meta'].get('ID')
print(linux_id)

if host.fact.linux_name == 'CentOS':
    yum.key(
        name='Add the Docker CentOS gpg key',
        src='https://download.docker.com/linux/{}/gpg'.format(linux_id),
    )

yum.rpm(
    name='Ensure an rpm is not installed',
    src='snappy',
    present=False,
)
Example #7
0
        name='Install packages for python virtual environments',
        packages=[
            'gcc',
            'libffi-dev',
            'make',
            'musl-dev',
            'openssl-dev',
            'py3-pynacl',
            'py3-virtualenv',
            'python3-dev',
        ],
    )

if host.fact.linux_name in ['CentOS']:
    yum.packages(
        name='Install pip3 so you can install virtualenv',
        packages=['python3-pip', 'python3-devel', 'gcc-c++', 'make'],
    )

if host.fact.linux_name in ['Ubuntu']:
    apt.packages(
        name='Install pip3 so you can install virtualenv',
        packages='python3-pip',
        update=True,
    )

if not host.fact.file('/usr/bin/pip'):
    files.link(
        name='Create link /usr/bin/pip that points to /usr/bin/pip3',
        path='/usr/bin/pip',
        target='/usr/bin/pip3',
    )
Example #8
0
from pyinfra import host
from pyinfra.facts.server import LinuxName
from pyinfra.operations import apk, apt, files, git, yum

if host.get_fact(LinuxName) in ["Alpine"]:
    apk.packages(
        name="Install git",
        packages=["git"],
    )

if host.get_fact(LinuxName) in ["CentOS"]:
    yum.packages(
        name="Install git",
        packages=["git"],
        update=True,
    )

if host.get_fact(LinuxName) in ["Ubuntu"]:
    apt.packages(
        name="Install git",
        packages=["git"],
        update=True,
    )

src_dir = "/usr/local/src"
dest = src_dir + "/pyinfra"

files.directory(
    name="Ensure the src_dir directory exists",
    path=src_dir,
)
Example #9
0
from pyinfra import host
from pyinfra.operations import apk, apt, files, git, yum

SUDO = True

if host.fact.linux_name in ['Alpine']:
    apk.packages(
        name='Install git',
        packages=['git'],
    )

if host.fact.linux_name in ['CentOS']:
    yum.packages(
        name='Install git',
        packages=['git'],
        update=True,
    )

if host.fact.linux_name in ['Ubuntu']:
    apt.packages(
        name='Install git',
        packages=['git'],
        update=True,
    )

src_dir = '/usr/local/src'
dest = src_dir + '/pyinfra'

files.directory(
    name='Ensure the src_dir directory exists',
    path=src_dir,
Example #10
0
from pyinfra import host
from pyinfra.operations import apk, apt, files, git, yum

SUDO = True

if host.fact.linux_name in ['Alpine']:
    apk.packages(
        {'Install git'},
        'git',
    )

if host.fact.linux_name in ['CentOS']:
    yum.packages(
        {'Install git'},
        'git',
        update=True,
    )

if host.fact.linux_name in ['Ubuntu']:
    apt.packages(
        {'Install git'},
        'git',
        update=True,
    )

src_dir = '/usr/local/src'
dest = src_dir + '/pyinfra'

files.directory(
    {'Ensure the src_dir directory exists'},
    src_dir,
Example #11
0
from pyinfra import host
from pyinfra.facts.files import File
from pyinfra.facts.server import LinuxName
from pyinfra.operations import apt, server, yum

if host.get_fact(LinuxName) in ["CentOS", "RedHat"]:
    yum.packages(
        name="Install some packages",
        packages=["cronie"],
        update=True,
    )

if host.get_fact(LinuxName) in ["Ubuntu"]:
    apt.packages(
        name="Install some packages",
        packages=["cron"],
        update=True,
    )

# simple example for a crontab
server.crontab(
    name="Backup /etc weekly",
    command="/bin/tar cf /tmp/etc_bup.tar /etc",
    cron_name="backup_etc",
    day_of_week=0,
    hour=1,
    minute=0,
)

server.group(
    name="Create docker group",
Example #12
0
if host in masters:
    server.hostname(
        name="Set the hostname for the Puppet Master",
        hostname="master.example.com",
    )

if host in agents:
    server.hostname(
        name="Set the hostname for an agent",
        hostname="agent.example.com",
    )

if host.get_fact(LinuxName) in ["CentOS", "RedHat"]:

    yum.packages(
        name="Install chrony for Network Time Protocol (NTP)",
        packages=["chrony"],
    )

    major = host.get_fact(LinuxDistribution)["major"]
    yum.rpm(
        name="Install Puppet Repo",
        src="https://yum.puppet.com/puppet6-release-el-{}.noarch.rpm".format(
            major),
    )

    files.line(
        name="Ensure SELINUX is disabled",
        path="/etc/sysconfig/selinux",
        line=r"SELINUX=.*",
        replace="SELINUX=disabled",
    )
Example #13
0
from pyinfra import host
from pyinfra.facts.server import LinuxDistribution, LinuxName
from pyinfra.operations import yum

# Note: This "if" below is not really required.
# For instance, if you run this deploy on an
# Ubuntu instance (which does not use yum)
# the yum.packages() will simply be skipped
if host.get_fact(LinuxName) in ["CentOS", "RedHat"]:

    yum.packages(
        name="Install some packages",
        packages=["vim-enhanced", "vim", "wget"],
        update=True,
    )

linux_distribution = host.get_fact(LinuxDistribution)
linux_id = linux_distribution["release_meta"].get("ID")

if host.get_fact(LinuxName) == "CentOS":
    yum.key(
        name="Add the Docker CentOS gpg key",
        src="https://download.docker.com/linux/{}/gpg".format(linux_id),
    )

yum.rpm(
    name="Ensure an rpm is not installed",
    src="snappy",
    present=False,
)
Example #14
0
if host in masters:
    server.hostname(
        {'Set the hostname for the Puppet Master'},
        'master.example.com',
    )

if host in agents:
    server.hostname(
        {'Set the hostname for an agent'},
        'agent.example.com',
    )

if host.fact.linux_name in ['CentOS', 'RedHat']:

    yum.packages(
        {'Install chrony for Network Time Protocol (NTP)'},
        ['chrony'],
    )

    major = host.fact.linux_distribution['major']
    yum.rpm(
        {'Install Puppet Repo'},
        'https://yum.puppet.com/puppet6-release-el-{}.noarch.rpm'.format(
            major),
    )

    files.line(
        {'Ensure SELINUX is disabled'},
        '/etc/sysconfig/selinux',
        r'SELINUX=.*',
        replace='SELINUX=disabled',
    )