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 executed/tested via the command line:
pyinfra myhost.com fact date another_fact ...
Or as part of a deploy:
if host.fact.linux_distribution['name'] == 'Ubuntu':
spt.packages(...)
Facts, like operations, are namespaced as different modules:
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, pattern)
¶
Checks for the existence of text in a file using grep. Returns a list of matching lines if the file exists, andNone
if the file does not.
find_links(name)
¶
Returns a list of links from a start point, recursively using find.
link(name)
¶
sha1_file(name)
¶
Returns a SHA1 hash of a file. Works with both sha1sum and sha1.
socket(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 asinitd_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' }, ...
Npm¶
npm_packages(directory)
¶
Returns a dict of installed npm packages globally or in a given directory:
'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' ] }, ...