What is the "ansible.builtin" Ansible collection? What is the "ansible.legacy" collection?

Today we're going to talk about Ansible's most essential modules and plugins and how we can use them in our everyday Playbook.

I'm Luca Berton, Ansible Automation Expert, and welcome to today's lesson.

What is ansible.builtin collection?

The "ansible.builtin" collection refers to modules & plugins shipped with ansible-core.

Technically is a synthetic collection, virtually constructed by the core engine.

What is ansible.legacy collection?

The "ansible.legacy" collection is a superset of "ansible.builtin" with 'custom' plugins in the configured paths and adjacent directories. We use the "ansible.legacy" when we don't specify any Ansible collection in our playbook.

Technically is a synthetic collection, virtually constructed by the core engine.

Links

  • https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#what-is-the-difference-between-ansible-legacy-and-ansible-builtin-collections
  • https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-action-plugin-path

Demo

Live Playbook about "ansible.builtin" vs. "ansible.legacy" collections.

Let's jump in a quick Playbook to demonstrate the difference between the "ansible.builtin" vs. "ansible.legacy" collections.

I'm going to create a custom "debug" module that prints the extra text "foo" when used with the "msg" parameter.

Let's see the different results when we execute with "ansible.builtin", "ansible.legacy" or without specifying any collections.

The code is the following.

common code

  • inventory (localhost)

``ini

localhost ansible_connection=local

`

  • ansible.cfg

`ini

[defaults]

action_plugins = plugins/action

`

  • plugins/action/debug.py

``python

Copyright 2012, Dag Wieers <[email protected]>

Copyright 2016, Toshio Kuratomi <[email protected]>

#

This file is part of Ansible

#

Ansible is free software: you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

#

Ansible is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

#

You should have received a copy of the GNU General Public License

along with Ansible. If not, see <http://www.gnu.org/licenses/>.

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

from ansible.errors import AnsibleUndefinedVariable

from ansible.module_utils.six import string_types

from ansible.module_utils._text import to_text

from ansible.plugins.action import ActionBase

class ActionModule(ActionBase):

''' Print statements during execution '''

TRANSFERS_FILES = False

_VALID_ARGS = frozenset(('msg', 'var', 'verbosity'))

de