| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright (c) 2019 Ansible Project |
| 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 |
class ModuleDocFragment(object): |
| 10 |
|
| 11 |
# Standard template documentation fragment, use by template and win_template. |
| 12 |
DOCUMENTATION = r""" |
| 13 |
description: |
| 14 |
- Templates are processed by the L(Jinja2 templating language,https://jinja.palletsprojects.com/en/stable/). |
| 15 |
- Documentation on the template formatting can be found in the |
| 16 |
L(Template Designer Documentation,https://jinja.palletsprojects.com/en/stable/templates/). |
| 17 |
- Additional variables listed below can be used in templates. |
| 18 |
- C(ansible_managed) (configurable via the C(defaults) section of C(ansible.cfg)) contains a string which can be used to |
| 19 |
describe the template name, host, modification time of the template file and the owner uid. |
| 20 |
- C(template_host) contains the node name of the template's machine. |
| 21 |
- C(template_uid) is the numeric user id of the owner. |
| 22 |
- C(template_path) is the path of the template. |
| 23 |
- C(template_fullpath) is the absolute path of the template. |
| 24 |
- C(template_destpath) is the path of the template on the remote system (added in 2.8). |
| 25 |
- C(template_run_date) is the date that the template was rendered. |
| 26 |
options: |
| 27 |
src: |
| 28 |
description: |
| 29 |
- Path of a Jinja2 formatted template on the Ansible controller. |
| 30 |
- This can be a relative or an absolute path. |
| 31 |
- The file must be encoded with C(utf-8) but O(output_encoding) can be used to control the encoding of the output |
| 32 |
template. |
| 33 |
type: path |
| 34 |
required: yes |
| 35 |
dest: |
| 36 |
description: |
| 37 |
- Location to render the template to on the remote machine. |
| 38 |
type: path |
| 39 |
required: yes |
| 40 |
newline_sequence: |
| 41 |
description: |
| 42 |
- Specify the newline sequence to use for templating files. |
| 43 |
type: str |
| 44 |
choices: [ '\n', '\r', '\r\n' ] |
| 45 |
default: '\n' |
| 46 |
version_added: '2.4' |
| 47 |
block_start_string: |
| 48 |
description: |
| 49 |
- The string marking the beginning of a block. |
| 50 |
type: str |
| 51 |
default: '{%' |
| 52 |
version_added: '2.4' |
| 53 |
block_end_string: |
| 54 |
description: |
| 55 |
- The string marking the end of a block. |
| 56 |
type: str |
| 57 |
default: '%}' |
| 58 |
version_added: '2.4' |
| 59 |
variable_start_string: |
| 60 |
description: |
| 61 |
- The string marking the beginning of a print statement. |
| 62 |
type: str |
| 63 |
default: '{{' |
| 64 |
version_added: '2.4' |
| 65 |
variable_end_string: |
| 66 |
description: |
| 67 |
- The string marking the end of a print statement. |
| 68 |
type: str |
| 69 |
default: '}}' |
| 70 |
version_added: '2.4' |
| 71 |
comment_start_string: |
| 72 |
description: |
| 73 |
- The string marking the beginning of a comment statement. |
| 74 |
type: str |
| 75 |
version_added: '2.12' |
| 76 |
comment_end_string: |
| 77 |
description: |
| 78 |
- The string marking the end of a comment statement. |
| 79 |
type: str |
| 80 |
version_added: '2.12' |
| 81 |
trim_blocks: |
| 82 |
description: |
| 83 |
- Determine when newlines should be removed from blocks. |
| 84 |
- When set to V(yes) the first newline after a block is removed (block, not variable tag!). |
| 85 |
type: bool |
| 86 |
default: yes |
| 87 |
version_added: '2.4' |
| 88 |
lstrip_blocks: |
| 89 |
description: |
| 90 |
- Determine when leading spaces and tabs should be stripped. |
| 91 |
- When set to V(yes) leading spaces and tabs are stripped from the start of a line to a block. |
| 92 |
type: bool |
| 93 |
default: no |
| 94 |
version_added: '2.6' |
| 95 |
force: |
| 96 |
description: |
| 97 |
- Determine when the file is being transferred if the destination already exists. |
| 98 |
- When set to C(yes), replace the remote file when contents are different than the source. |
| 99 |
- When set to C(no), the file will only be transferred if the destination does not exist. |
| 100 |
type: bool |
| 101 |
default: yes |
| 102 |
output_encoding: |
| 103 |
description: |
| 104 |
- Overrides the encoding used to write the template file defined by O(dest). |
| 105 |
- It defaults to C(utf-8), but any encoding supported by python can be used. |
| 106 |
- The source template file must always be encoded using C(utf-8), for homogeneity. |
| 107 |
type: str |
| 108 |
default: utf-8 |
| 109 |
version_added: '2.7' |
| 110 |
notes: |
| 111 |
- Including a string that uses a date in the template will result in the template being marked 'changed' each time. |
| 112 |
- Since Ansible 0.9, templates are loaded with O(trim_blocks=True). |
| 113 |
- > |
| 114 |
Also, you can override jinja2 settings by adding a special header to template file. |
| 115 |
that is C(#jinja2:variable_start_string:'[%', variable_end_string:'%]', trim_blocks: False) |
| 116 |
which changes the variable interpolation markers to C([% var %]) instead of C({{ var }}). |
| 117 |
This is the best way to prevent evaluation of things that look like, but should not be Jinja2. |
| 118 |
- To find Byte Order Marks in files, use C(Format-Hex <file> -Count 16) on Windows, and use C(od -a -t x1 -N 16 <file>) |
| 119 |
on Linux. |
| 120 |
""" |