Debian Codegraph @

lib/ansible/modules/meta.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright: (c) 2016, Ansible, a Red Hat company
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import annotations
7
8
9 DOCUMENTATION = r"""
10 module: meta
11 short_description: Execute Ansible 'actions'
12 version_added: '1.2'
13 description:
14 - Meta tasks are a special kind of task which can influence Ansible internal execution or state.
15 - Meta tasks can be used anywhere within your playbook.
16 - This module is also supported for Windows targets.
17 options:
18 free_form:
19 description:
20 - This module takes a free form command, as a string. There is not an actual option named "free form". See the examples!
21 - V(flush_handlers) makes Ansible run any handler tasks which have thus far been notified. Ansible inserts these tasks internally at certain
22 points to implicitly trigger handler runs (after pre/post tasks, the final role execution, and the main tasks section of your plays).
23 - V(refresh_inventory) (added in Ansible 2.0) reloads inventory sources and the host and group structure based on those sources.
24 It also preserves dynamic hosts created by M(ansible.builtin.add_host) and dynamic groups created by M(ansible.builtin.group_by).
25 In the case of dynamic inventory scripts this means they will be re-executed. If the dynamic inventory script is using a cache,
26 Ansible cannot know this and has no way of refreshing it (you can disable the cache or, if available for your specific inventory
27 datasource (for example P(amazon.aws.aws_ec2#inventory)), you can use an inventory plugin instead of an inventory script).
28 This is mainly useful when additional hosts are created and users wish to use them instead of using the M(ansible.builtin.add_host) module.
29 - Note that neither V(refresh_inventory) nor the M(ansible.builtin.add_host) add hosts to the hosts the current play iterates over.
30 However, if needed, you can explicitly delegate tasks to new hosts with C(delegate_to). Generally,
31 C(delegate_to) can be used against hosts regardless of whether they are in the inventory or not, as long as
32 the value supplied is sufficient for the connection plugin to access the host.
33 - V(noop) (added in Ansible 2.0) This literally does 'nothing'. It is mainly used internally and not recommended for general use.
34 - V(clear_facts) (added in Ansible 2.1) causes the gathered facts for the hosts specified in the play's list of hosts to be cleared,
35 including the fact cache.
36 - V(clear_host_errors) (added in Ansible 2.1) clears the failed state (if any) from hosts specified in the play's list of hosts.
37 This will make them available for targeting in subsequent plays, but not continue execution in the current play.
38 - V(end_play) (added in Ansible 2.2) causes the play to end without failing the host(s). Note that this affects all hosts.
39 - V(reset_connection) (added in Ansible 2.3) interrupts a persistent connection (i.e. ssh + control persist)
40 - V(end_host) (added in Ansible 2.8) is a per-host variation of V(end_play). Causes the play to end for the current host without failing it.
41 - V(end_batch) (added in Ansible 2.12) causes the current batch (see C(serial)) to end without failing the host(s).
42 Note that with C(serial=0) or undefined this behaves the same as V(end_play).
43 - V(end_role) (added in Ansible 2.18) causes the currently executing role to end without failing the host(s).
44 Effectively all tasks from within a role after V(end_role) is executed are ignored. Since handlers live in a global,
45 play scope, all handlers added via the role are unaffected and are still executed if notified. It is an error
46 to call V(end_role) from outside of a role or from a handler. Note that V(end_role) does not have an effect to
47 the parent roles or roles that depend (via dependencies in meta/main.yml) on a role executing V(end_role).
48 choices: [ clear_facts, clear_host_errors, end_host, end_play, flush_handlers, noop, refresh_inventory, reset_connection, end_batch, end_role ]
49 required: true
50 extends_documentation_fragment:
51 - action_common_attributes
52 - action_common_attributes.conn
53 - action_common_attributes.flow
54 - action_core
55 attributes:
56 action:
57 support: none
58 bypass_host_loop:
59 details: Some of the subactions ignore the host loop, see the description above for each specific action for the exceptions
60 support: partial
61 bypass_task_loop:
62 details: Most of the subactions ignore the task loop, see the description above for each specific action for the exceptions
63 support: partial
64 check_mode:
65 details: While these actions don't modify the targets directly they do change possible states of the target within the run
66 support: partial
67 delegation:
68 support: none
69 diff_mode:
70 support: none
71 ignore_conditional:
72 details: Only some options support conditionals and when they do they act 'bypassing the host loop', taking the values from first available host
73 support: partial
74 connection:
75 details: Most options in this action do not use a connection, except V(reset_connection) which still does not connect to the remote
76 support: partial
77 until:
78 support: none
79 notes:
80 - V(clear_facts) will remove the persistent facts from M(ansible.builtin.set_fact) using O(ansible.builtin.set_fact#module:cacheable=True),
81 but not the current host variable it creates for the current run.
82 - Variable plugins are not part of inventory and handle execution and caching independently of V(refresh_inventory).
83 V(refresh_inventory) does not invalidate variable plugin caches. Whether later variable resolution sees updated variable plugin data depends
84 on the plugin's stage and caching behavior.
85 - The default variable plugin P(ansible.builtin.host_group_vars#vars) caches applicable paths and file content, so creating, modifying, or removing
86 C(host_vars) and C(group_vars) files mid-play for hosts or groups that have already been targeted has no effect on the current or any
87 subsequent plays. Use M(ansible.builtin.include_vars) to load variable files modified during playbook execution.
88 - Skipping M(ansible.builtin.meta) tasks with tags is not supported before Ansible 2.11.
89 seealso:
90 - module: ansible.builtin.assert
91 - module: ansible.builtin.fail
92 author:
93 - Ansible Core Team
94 """
95
96 EXAMPLES = r"""
97 # Example showing flushing handlers on demand, not at end of play
98 - ansible.builtin.template:
99 src: new.j2
100 dest: /etc/config.txt
101 notify: myhandler
102
103 - name: Force all notified handlers to run at this point, not waiting for normal sync points
104 ansible.builtin.meta: flush_handlers
105
106 # Example showing how to refresh inventory during play
107 - name: Reload inventory, useful with dynamic inventories when play makes changes to the existing hosts
108 cloud_guest: # this is fake module
109 name: newhost
110 state: present
111
112 - name: Refresh inventory to ensure new instances exist in inventory
113 ansible.builtin.meta: refresh_inventory
114
115 # Example showing how to clear all existing facts of targeted hosts
116 - name: Clear gathered facts from all currently targeted hosts
117 ansible.builtin.meta: clear_facts
118
119 # Example showing how to continue using a failed target, for the next play
120 - name: Bring host back to play after failure
121 ansible.builtin.copy:
122 src: file
123 dest: /etc/file
124 remote_user: imightnothavepermission
125
126 - ansible.builtin.meta: clear_host_errors
127
128 # Example showing how to reset an existing connection
129 - ansible.builtin.user:
130 name: '{{ ansible_user }}'
131 groups: input
132
133 - name: Reset ssh connection to allow user changes to affect 'current login user'
134 ansible.builtin.meta: reset_connection
135
136 # Example showing how to end the play for specific targets
137 - name: End the play for hosts that run CentOS 6
138 ansible.builtin.meta: end_host
139 when:
140 - ansible_distribution == 'CentOS'
141 - ansible_distribution_major_version == '6'
142 """