Skip to content

patch

Collection Note

This module is part of the ansible.posix collection. To install the collection, use:

ansible-galaxy collection install ansible.posix
Added in version 1.0.0.

Synopsis

  • Apply patch files using the GNU patch tool.

Parameters

Parameter Defaults / Choices Comments
backup
bool
Passes C(--backup --version-control=numbered) to patch, producing numbered backup copies.
basedir
path
Path of a base directory in which the patch file will be applied.
May be omitted when O(dest) option is specified, otherwise required.
binary
bool
Setting to V(true) will disable patch's heuristic for transforming CRLF line endings into LF.
Line endings of O(src) and O(dest) must match.
If set to V(false), C(patch) will replace CRLF in O(src) files on POSIX.
dest
path
Path of the file on the remote machine to be patched.
The names of the files to be patched are usually taken from the patch file, but if there's just one file to be patched it can specified with this option.
ignore_whitespace
bool
Setting to V(true) will ignore white space changes between patch and input.
remote_src
bool
If V(false), it will search for src at originating/controller machine,
If C(true), it will go to the remote/target machine for the O(src).
src
path
required
Path of the patch file as accepted by the GNU patch tool. If O(remote_src=false), the patch source file is looked up from the module's I(files) directory.
state
str
Default: present
Choices: absent, present
Whether the patch should be applied or reverted.
strip
int
Number that indicates the smallest prefix containing leading slashes that will be stripped from each file name found in the patch file.
For more information see the strip parameter of the GNU patch tool.

Notes

Note

  • This module requires GNU I(patch) utility to be installed on the remote host.

Examples

- name: Apply patch to one file
  ansible.posix.patch:
    src: /tmp/index.html.patch
    dest: /var/www/index.html

- name: Apply patch to multiple files under basedir
  ansible.posix.patch:
    src: /tmp/customize.patch
    basedir: /var/www
    strip: 1

- name: Revert patch to one file
  ansible.posix.patch:
    src: /tmp/index.html.patch
    dest: /var/www/index.html
    state: absent

Authors

  • Jakub Jirutka (@jirutka)
  • Luis Alberto Perez Lazaro (@luisperlaz)