ansible.builtin.meta (v2.16.5) — module

Execute Ansible 'actions'

| "added in version" 1.2 of ansible.builtin"

Authors: Ansible Core Team

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

Meta tasks are a special kind of task which can influence Ansible internal execution or state.

Meta tasks can be used anywhere within your playbook.

This module is also supported for Windows targets.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example showing flushing handlers on demand, not at end of play
- ansible.builtin.template:
    src: new.j2
    dest: /etc/config.txt
  notify: myhandler
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Force all notified handlers to run at this point, not waiting for normal sync points
  ansible.builtin.meta: flush_handlers
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example showing how to refresh inventory during play
- name: Reload inventory, useful with dynamic inventories when play makes changes to the existing hosts
  cloud_guest:            # this is fake module
    name: newhost
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Refresh inventory to ensure new instances exist in inventory
  ansible.builtin.meta: refresh_inventory
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example showing how to clear all existing facts of targeted hosts
- name: Clear gathered facts from all currently targeted hosts
  ansible.builtin.meta: clear_facts
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example showing how to continue using a failed target
- name: Bring host back to play after failure
  ansible.builtin.copy:
    src: file
    dest: /etc/file
  remote_user: imightnothavepermission
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.meta: clear_host_errors
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example showing how to reset an existing connection
- ansible.builtin.user:
    name: '{{ ansible_user }}'
    groups: input
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reset ssh connection to allow user changes to affect 'current login user'
  ansible.builtin.meta: reset_connection
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example showing how to end the play for specific targets
- name: End the play for hosts that run CentOS 6
  ansible.builtin.meta: end_host
  when:
  - ansible_distribution == 'CentOS'
  - ansible_distribution_major_version == '6'

Inputs

    
free_form:
    choices:
    - clear_facts
    - clear_host_errors
    - end_host
    - end_play
    - flush_handlers
    - noop
    - refresh_inventory
    - reset_connection
    - end_batch
    description:
    - This module takes a free form command, as a string. There is not an actual option
      named "free form".  See the examples!
    - V(flush_handlers) makes Ansible run any handler tasks which have thus far been notified.
      Ansible inserts these tasks internally at certain points to implicitly trigger handler
      runs (after pre/post tasks, the final role execution, and the main tasks section
      of your plays).
    - V(refresh_inventory) (added in Ansible 2.0) forces the reload of the inventory,
      which in the case of dynamic inventory scripts means they will be re-executed. If
      the dynamic inventory script is using a cache, Ansible cannot know this and has
      no way of refreshing it (you can disable the cache or, if available for your specific
      inventory datasource (e.g. aws), you can use the an inventory plugin instead of
      an inventory script). 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.
    - V(noop) (added in Ansible 2.0) This literally does 'nothing'. It is mainly used
      internally and not recommended for general use.
    - 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, including the fact cache.
    - 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.
    - V(end_play) (added in Ansible 2.2) causes the play to end without failing the host(s).
      Note that this affects all hosts.
    - V(reset_connection) (added in Ansible 2.3) interrupts a persistent connection (i.e.
      ssh + control persist)
    - 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.
    - V(end_batch) (added in Ansible 2.12) causes the current batch (see C(serial)) to
      end without failing the host(s). Note that with C(serial=0) or undefined this behaves
      the same as V(end_play).
    required: true

See also