Debian Codegraph @

ansible_collections/microsoft/ad/docs/docsite/rst/guide_list_values.rst

raw
1 .. _ansible_collections.microsoft.ad.docsite.guide_list_values:
2
3 ********************************
4 Setting list option values guide
5 ********************************
6
7 Some AD options accept multiple values which require special rules when it comes to checking for idempotency in Ansible. This collection has been designed so that each of the modules which manage AD objects follow the same style when it comes to their options. In particular, they should all follow the style documented in this guide when it comes to options that contain multiple values like ``spn``, ``delegates``, etc.
8
9 .. contents::
10 :local:
11 :depth: 1
12
13 .. _ansible_collections.microsoft.ad.docsite.guide_list_values.something:
14
15 Add, remove, and set
16 ====================
17
18 For each module option that manage a multi valued LDAP attribute there exists three actions:
19
20 * ``add``
21 * ``remove``
22 * ``set``
23
24 The ``add`` and ``remove`` option will add or remove the specified value(s) from the existing value. The ``set`` option will replace the existing values with what was specified in the task.
25 Using an example of an AD object with the following ``servicePrincipalNames`` values:
26
27 * ``HTTP/host1``
28 * ``HTTP/host1.domain.com``
29 * ``HTTP/host1.domain.com:443``
30
31 Doing ``add: ['HTTP/host1','HTTP/host2']`` will add ``HTTP/host2`` to the existing values bringing it to:
32
33 * ``HTTP/host1``
34 * ``HTTP/host1.domain.com``
35 * ``HTTP/host1.domain.com:443``
36 * ``HTTP/host2``
37
38 Doing ``remove: ['HTTP/host1','HTTP/host3']`` will remove ``HTTP/host1`` from the existing values bringing it to:
39
40 * ``HTTP/host1.domain.com``
41 * ``HTTP/host1.domain.com:443``
42
43 Doing ``set: ['HTTP/host1', 'HTTP/host2']`` will remove any values not in that list and add values in that list but not set bringing it to:
44
45 * ``HTTP/host1``
46 * ``HTTP/host2``
47
48 It is possible to use ``add`` and ``remove`` together but setting ``set`` will always take precedence over the others.
49 It is also possible to clear all the existing values by setting the ``set`` value to an empty list, for example ``set: []``.
50
51 Examples
52 ========
53
54 The ``add``, ``remove``, and ``set`` options are subkeys of the module option it controls. For example the :ref:`microsoft.ad.user <ansible_collections.microsoft.ad.user_module>` has an option called ``groups`` which control the list of groups the user is a member of. To add a group to the user, simply use the ``add`` key like so:
55
56 .. code-block:: yaml
57
58 - name: add a user to a group
59 microsoft.ad.user:
60 name: MyUser
61 groups:
62 add:
63 - Group 1
64 - Group 2
65
66 This will ensure the user is added to the groups ``Group 1`` and ``Group 2`` while also preserving the existing membership. To remove a user from a user, simple use the ``remove`` key like so:
67
68 .. code-block:: yaml
69
70 - name: remove a user from a group
71 microsoft.ad.user:
72 name: MyUser
73 groups:
74 remove:
75 - Group 1
76 - Group 2
77
78 This does the opposite to add and will remove the user from ``Group 1`` and ``Group 2`` but it will still preserve any existing group memberships of that user. It is also possible to combine ``add`` and ``remove`` together:
79
80 .. code-block:: yaml
81
82 - name: add and remove user groups
83 microsoft.ad.user:
84 name: MyUser
85 groups:
86 add:
87 - Group 1
88 remove:
89 - Group 2
90
91 This will ensure the user is a member of ``Group 1`` and is not a member of ``Group 2``. Like before it will not touch the existing group membership if they are not specified.
92
93 The set option following the same format like so:
94
95 .. code-block:: yaml
96
97 - name: set user groups
98 microsoft.ad.user:
99 name: MyUser
100 groups:
101 set:
102 - Group 1
103 - Group 2
104
105 This will ensure the user is only members of ``Group 1`` and ``Group 2``, removing any other group not in that list. While it is possible to combine ``set`` with either ``add`` or ``remove``, the module will completely ignore the values in ``add`` or ``remove``.
106
107 Finally to remove a user from all groups, use an empty list for the ``set`` option like so:
108
109 .. code-block:: yaml
110
111 - name: remove user groups
112 microsoft.ad.user:
113 name: MyUser
114 groups:
115 set: []
116
117 .. note::
118 This is not actually possible for user groups as it will always be a member of its primary group, it is just used for demonstration purposes.