Facts Index

pyinfra uses facts to determine the existing state of a remote server. Operations use this information to generate commands which alter the state. Facts can be easily tested like so:

$ pyinfra -i myhost.com --fact date
...
"myhost.com": "2016-01-01T16:20:00+00:00"

Facts are namespaced similarly to modules, use the sidebar to browse those available.

Apt

apt_sources

Returns a list of installed apt sources:

{
    'type': 'deb',
    'url': 'http://archive.ubuntu.org',
    'distribution': 'trusty',
    'components', ['main', 'multiverse']
},
...

deb_package(name)

Returns information on a .deb file.

deb_packages

Returns a dict of installed dpkg packages:

'package_name': 'version',
...

Devices

block_devices

Returns a dict of (mounted) block devices:

'/dev/sda1': {
    'available': '39489508',
    'used_percent': '3',
    'mount': '/',
    'used': '836392',
    'blocks': '40325900'
},
...

network_devices

Gets & returns a dict of network devices:

'eth0': {
    'ipv4': {
        'address': '127.0.0.1',
        'netmask': '255.255.255.255',
        'broadcast': '127.0.0.13'
    },
    'ipv6': {
        'size': '64',
        'address': 'fe80::a00:27ff:fec3:36f0'
    }
},
...

Files

directory(name)

file(name)

find_directories(name)

Returns a list of directories from a start point, recursively using find.

find_files(name)

Returns a list of files from a start point, recursively using find.

find_in_file(name)

Checks for the existence of text in a file using grep. Returns a list of matching lines if the file exists, and None if the file does not.

sha1_file(name)

Returns a SHA1 hash of a file. Works with both sha1sum and sha1.

socket(name)

Gem

gem_packages

Returns a dict of installed gem packages:

'package_name': 'version',
...

Git

git_branch(name)

Init

initd_status

Low level check for every /etc/init.d/* script. Unfortunately many of these mishehave and return exit status 0 while also displaying the help info/not offering status support.

Returns a dict of name -> status.

Expected codes found at:
http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

rcd_enabled

Returns a dict of service name -> whether enabled (on boot) status. Different to Linux variants because BSD has no/one runlevel.

rcd_status

Same as initd_status but for BSD (/etc/rc.d) systems. Unlike Linux/init.d, BSD init scripts are well behaved and as such their output can be trusted.

systemd_enabled

Returns a dict of name -> whether enabled for systemd managed services.

systemd_status

Returns a dict of name -> status for systemd managed services.

upstart_status

Returns a dict of name -> status for upstart managed services.

Iptables

ip6tables_chains(table)

Returns a dict of ip6tables chains & policies:

'NAME': 'POLICY',
...

ip6tables_rules(table)

Returns a list of ip6tables rules for a specific table:

{
    'chain': 'PREROUTING',
    'jump': 'DNAT'
},
...

iptables_chains(table)

Returns a dict of iptables chains & policies:

'NAME': 'POLICY',
...

iptables_rules(table)

Returns a list of iptables rules for a specific table:

{
    'chain': 'PREROUTING',
    'jump': 'DNAT'
},
...

Lxd

lxd_containers

Returns a list of running LXD containers

Npm

npm_packages(directory)

Returns a dict of installed npm packages globally or in a given directory:

'package_name': 'version',
...

Pip

pip_packages(pip)

Returns a dict of installed pip packages:

'package_name': 'version',
...

Pkg

pkg_packages

Returns a dict of installed pkg packages:

'package_name': 'version',
...

Server

arch

command(command)

date

Returns the current datetime on the server.

groups

Returns a list of groups on the system.

home

hostname

linux_distribution

Returns a dict of the Linux distribution version. Ubuntu, Debian, CentOS, Fedora & Gentoo currently. Also contains any key/value items located in release files.

{
    'name': 'CentOS',
    'major': 6,
    'minor': 5,
    'release_meta': {
        'DISTRIB_CODENAME': 'trusty',
        ...
    }
}

os

os_version

users

Returns a dict of users -> details:

'user_name': {
    'home': '/home/user_name',
    'shell': '/bin/bash,
    'group': 'main_user_group',
    'groups': [
        'other',
        'groups'
    ]
},
...

which(name)

Yum

rpm_packages

Returns a dict of installed rpm packages:

'package_name': 'version',
...

rpm_package(name)

Returns information on a .rpm file:

{
    'name': 'my_package',
    'version': '1.0.0'
}