Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add documentation around commonly-used Facts for Conditionals #34263

Merged
merged 2 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion docs/docsite/rst/playbooks_conditionals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Conditionals

Often the result of a play may depend on the value of a variable, fact (something learned about the remote system), or previous task result.
In some cases, the values of variables may depend on other variables.
Further, additional groups can be created to manage hosts based on whether the hosts match other criteria. This topic covers how conditionals are used in playbooks.
Additional groups can be created to manage hosts based on whether the hosts match other criteria. This topic covers how conditionals are used in playbooks.

.. note:: There are many options to control execution flow in Ansible. More examples of supported conditionals can be located here: http://jinja.pocoo.org/docs/dev/templates/#comparisons.

Expand Down Expand Up @@ -319,6 +319,69 @@ You may check the registered variable's string contents for emptiness::
debug: msg="Directory is empty"
when: contents.stdout == ""

Commonly Used Facts
```````````````````

The following Facts (see :ref:`_vars_and_facts`) are frequently used in Conditionals - see above for examples.

.. _ansible_distribution:

ansible_distribution
--------------------

Possible values::

Alpine
Altlinux
Amazon
Archlinux
ClearLinux
Coreos
Debian
Gentoo
Mandriva
NA
OpenWrt
OracleLinux
RedHat
Slackware
SMGL
SUSE
VMwareESX

.. See `OSDIST_LIST`

.. _ansible_distribution_major_version:

ansible_distribution_major_version
----------------------------------

This will be the major version of the operating system. For example, the value will be `16` for Ubuntu 16.04.

.. _ansible_os_family:

ansible_os_family
-----------------

Possible values::

AIX
Alpine
Altlinux
Archlinux
Darwin
Debian
FreeBSD
Gentoo
HP-UX
Mandrake
RedHat
SGML
Slackware
Solaris
Suse

.. See `OS_FAMILY_MAP`

.. seealso::

Expand Down
2 changes: 2 additions & 0 deletions lib/ansible/module_utils/facts/system/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DistributionFiles:
# - allowempty == True
# - be listed in SEARCH_STRING
# - have a function get_distribution_DISTNAME implemented
# keep names in sync with Conditionals page of docs
OSDIST_LIST = (
{'path': '/etc/oracle-release', 'name': 'OracleLinux'},
{'path': '/etc/slackware-version', 'name': 'Slackware'},
Expand Down Expand Up @@ -403,6 +404,7 @@ class Distribution(object):
'SMGL': 'Source Mage GNU/Linux',
}

# keep keys in sync with Conditionals page of docs
OS_FAMILY_MAP = {'RedHat': ['RedHat', 'Fedora', 'CentOS', 'Scientific', 'SLC',
'Ascendos', 'CloudLinux', 'PSBM', 'OracleLinux', 'OVS',
'OEL', 'Amazon', 'Virtuozzo', 'XenServer'],
Expand Down