Pytest System Report
In a previous article, I introduced a simple way to perform system checks with pytest + testinfra . Here it is a simple variant of the same principle with the intention of producing a short human readable report about system configuration. The goal is to get and report quickly some value of interests from a system (a host).
Using Ansible facts
One classic and efficient way to get system information is to use Ansible facts.
Here is an example using the ansible
ad hoc command.
|
However Ansible facts may not contain every information you want to check. I find this solution sometimes overkill and not so convenient to obtain a clear output.
Using a table output
I like table outputs in CLI, I think they are very clear.
To obtain this kind of output in Python I often use tabulate
–the use of tabulate
to pretty print Python DataFrame is by far my highest scored answer on Stack Overflow.
It is a convenient way to output tables in different formats from various Python data structures.
|
Then it should be run by
- disabling
pytest
capture thanks to the-s
flag - reducing
pytest
verbosity thanks to the-q
flag
|
This test can be run on any testinfra backends (remote hosts and docker images for example) to get a quick look at some important settings.