Commit 7d33ef38 authored by Maciej Delmanowski's avatar Maciej Delmanowski

Merge branch 'rei-ifesca-resources_groups'

parents ccb5911b e42bfc2a
Pipeline #42281982 failed with stages
in 210 minutes and 29 seconds
......@@ -201,6 +201,11 @@ Changed
The role has also been included in the ``common.yml`` playbook to ensure that
the host database is up to date as soon as possible.
- [debops.resources] Changed behaviour of used groups for templating. Now all
groups the host is in, will be used to search for template files.
Read the documentation about :ref:`resources__ref_templates` for more details
on templating with `debops`.
Fixed
~~~~~
......@@ -254,6 +259,10 @@ Removed
playbook. The relevant inventory variables have been renamed, check the
:ref:`upgrade_notes` for details.
- The ``resources__group_name`` variable has been removed in favor of using
all the groups the current hosts is in. This change has been reflected in the
updated variable ``resources__group_templates``.
`debops v0.8.0`_ - 2018-08-06
-----------------------------
......
......@@ -92,33 +92,31 @@ resources__parent_dirs_mode: '{{ omit }}'
# These variables define how the role will manage custom templates on remote
# hosts. See :ref:`resources__ref_templates` for more details.
# .. envvar:: resources__group_name [[[
#
# Name of the directory which contains templates which should be generated on
# hosts in a specific host group. This variable needs to be set on a group
# level in the inventory to take effect, only one group is supported at a time.
resources__group_name: 'nonexistent-host-group'
# ]]]
# .. envvar:: resources__templates [[[
#
# Directory which contains templates that should be generated on all hosts in
# the Ansible inventory.
resources__templates: '{{ resources__src + "templates/by-group/all" }}'
resources__templates: [ '{{ resources__src + "templates/by-group/all" }}' ]
# ]]]
# .. envvar:: resources__group_templates [[[
#
# Directory which contains templates that should be generated on hosts in
# a specific Ansible inventory group.
resources__group_templates: '{{ resources__src + "templates/by-group/" + resources__group_name }}'
# List of paths containing the directories of all the groups the current host is in, based on the content of ``group_names``.
# See `Ansible - Playbooks Varibles <https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#accessing-information-about-other-hosts-with-magic-variables>`_.
#
# For example if the host ``debian1`` is member of ``group-name1`` and ``group-name2``
# `debops.resources` will then search all template files inside the directories placed here: :file:`ansible/resources/templates/by-group/`.
# Resulting in: ``[ "ansible/resources/templates/by-group/group-name1", "ansible/resources/templates/by-group/group-name2" ]``.
#
# Read the documentation about :ref:`resources__ref_templates` for more details on templating with `debops.resources`.
resources__group_templates: '{{ group_names | map("regex_replace", "^(.*)$", resources__src + "templates/by-group/\1") | list }}'
# ]]]
# .. envvar:: resources__host_templates [[[
#
# Directory which contains templates that should be generated on specific hosts
# in the Ansible inventory.
resources__host_templates: '{{ resources__src + "templates/by-host/" + inventory_hostname }}'
resources__host_templates: [ '{{ resources__src + "templates/by-host/" + inventory_hostname }}' ]
# ]]]
# ]]]
# Manage custom paths [[[
......
......@@ -11,10 +11,9 @@
path: '/{{ item.path }}'
mode: '{{ item.mode }}'
state: 'directory'
with_filetree:
- '{{ resources__host_templates }}'
- '{{ resources__group_templates }}'
- '{{ resources__templates }}'
with_filetree: '{{ (resources__host_templates
+ resources__group_templates
+ resources__templates) | flatten }}'
when: item.state == 'directory'
- name: Generate custom templates
......@@ -22,10 +21,9 @@
src: '{{ item.src }}'
dest: '/{{ item.path }}'
mode: '{{ item.mode }}'
with_filetree:
- '{{ resources__host_templates }}'
- '{{ resources__group_templates }}'
- '{{ resources__templates }}'
with_filetree: '{{ (resources__host_templates
+ resources__group_templates
+ resources__templates) | flatten }}'
when: item.state == 'file'
- name: Recreate custom symlinks
......@@ -35,10 +33,9 @@
mode: '{{ item.mode }}'
state: 'link'
force: True
with_filetree:
- '{{ resources__host_templates }}'
- '{{ resources__group_templates }}'
- '{{ resources__templates }}'
with_filetree: '{{ (resources__host_templates
+ resources__group_templates
+ resources__templates) | flatten }}'
when: item.state == 'link'
# Manage custom paths [[[1
......
......@@ -52,11 +52,20 @@ located in the :file:`ansible/resources/` directory (or wherever the
   └── hostname2/
The ``with_filetree`` Ansible lookup plugin will look for resources to manage
in specific hostname directory, then a specific group name directory defined by
the :envvar:`resources__group_name` variable, then in the :file:`by-group/all/`
directory. The resource found first in this order wins and no further checks
in specific hostname directory, then of all the groups the current host is in
(based on the content of the variable `group_names`), then in the :file:`by-group/all/` directory.
The resource found first in this order wins and no further checks
are performed; this means that you can put a file in the :file:`by-group/all/`
directory and then override it using a host-specific directory.
The groups directories are read in the order dictated by Ansible during inventory parsing.
See `Ansible - Playbooks Variables`__ to learn about the ``group_names`` variable, and `Ansible - Working with Inventory`__
.. __: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#accessing-information-about-other-hosts-with-magic-variables
.. __: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#how-variables-are-merged
for more information on how to use ``ansible_group_priority`` to change the merge order
for groups of the same level (after the parent/child order is resolved).
Each directory structure starts at the root of the filesystem (:file:`/`), so
to create a file in a subdirectory you need to recreate the entire path. For
......@@ -72,11 +81,6 @@ local facts managed by other roles) and Ansible inventory. Referencing
variables from other roles might work only if these roles are included in the
playbook, however that is not idempotent and should be avoided.
To manage resources on a group level, you need to define the
:envvar:`resources__group_name` variable in the inventory group that contains
the directory name in the :file:`ansible/resources/template/by-group/`
directory. Only one group level is supported.
.. _resources__ref_paths:
resources__paths
......
......@@ -130,6 +130,14 @@ Inventory variable changes
been redesigned to use YAML lists instead of dictionaries. See
:ref:`netbase__ref_hosts` for more details.
- The ``resources__group_name`` variable has been removed in favor of using
all the groups the current hosts is in. This change has been reflected in the
updated variable :envvar:`resources__group_templates`.
If you need to use a specific group update the :envvar:`resources__group_templates`
accordingly.
Read the documentation about :ref:`resources__ref_templates` for more details on
templating with `debops.resources`.
Changes related to LXC containers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment