Skip to content

Commit ba49490

Browse files
author
github-actions
committed
Docs build 2025-03-27
1 parent 1eedccf commit ba49490

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

en/latest/_sources/operations/files.rst.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,9 @@ Generate a template using jinja2 and write it to the remote system.
683683
a dict with arguments that will be passed as keyword args to the jinja2
684684
`Environment() <https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment>`_.
685685

686+
The ``host``, ``state``, and ``inventory`` objects will be automatically passed to the template
687+
if not set explicitly.
688+
686689
Notes:
687690
Common convention is to store templates in a "templates" directory and
688691
have a filename suffix with '.j2' (for jinja2).
@@ -740,6 +743,21 @@ Notes:
740743
foo_dict=foo_dict,
741744
foo_list=foo_list
742745
)
746+
747+
# Example showing how to use host and inventory in a template file.
748+
template = StringIO("""
749+
name: "{{ host.name }}"
750+
list_contents:
751+
{% for entry in inventory.groups.my_servers %}
752+
- "{{ entry }}"
753+
{% endfor %}
754+
""")
755+
756+
files.template(
757+
name="Create a templated file",
758+
src=template,
759+
dest="/tmp/foo.yml"
760+
)
743761
Note:
744762
This operation also inherits all :doc:`global arguments </arguments>`.
745763

en/latest/operations/files.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ <h1>Files Operations<a class="headerlink" href="#files-operations" title="Permal
784784
<dt><code class="docutils literal notranslate"><span class="pre">jinja_env_kwargs</span></code>:</dt><dd>To have more control over how jinja2 renders your template, you can pass
785785
a dict with arguments that will be passed as keyword args to the jinja2
786786
<a class="reference external" href="https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment">Environment()</a>.</dd>
787+
</dl>
788+
<p>The <code class="docutils literal notranslate"><span class="pre">host</span></code>, <code class="docutils literal notranslate"><span class="pre">state</span></code>, and <code class="docutils literal notranslate"><span class="pre">inventory</span></code> objects will be automatically passed to the template
789+
if not set explicitly.</p>
790+
<dl class="docutils">
787791
<dt>Notes:</dt><dd><p>Common convention is to store templates in a “templates” directory and
788792
have a filename suffix with ‘.j2’ (for jinja2).</p>
789793
<p>For information on the template syntax, see
@@ -837,6 +841,21 @@ <h1>Files Operations<a class="headerlink" href="#files-operations" title="Permal
837841
<span class="n">foo_dict</span><span class="o">=</span><span class="n">foo_dict</span><span class="p">,</span>
838842
<span class="n">foo_list</span><span class="o">=</span><span class="n">foo_list</span>
839843
<span class="p">)</span>
844+
845+
<span class="c1"># Example showing how to use host and inventory in a template file.</span>
846+
<span class="n">template</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
847+
<span class="s2">name: &quot;{{ host.name }}&quot;</span>
848+
<span class="s2">list_contents:</span>
849+
<span class="s2">{</span><span class="si">% f</span><span class="s2">or entry in inventory.groups.my_servers %}</span>
850+
<span class="s2"> - &quot;{{ entry }}&quot;</span>
851+
<span class="s2">{</span><span class="si">% e</span><span class="s2">ndfor %}</span>
852+
<span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>
853+
854+
<span class="n">files</span><span class="o">.</span><span class="n">template</span><span class="p">(</span>
855+
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;Create a templated file&quot;</span><span class="p">,</span>
856+
<span class="n">src</span><span class="o">=</span><span class="n">template</span><span class="p">,</span>
857+
<span class="n">dest</span><span class="o">=</span><span class="s2">&quot;/tmp/foo.yml&quot;</span>
858+
<span class="p">)</span>
840859
</pre></div>
841860
</div>
842861
<dl class="docutils">

en/latest/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

en/next/_sources/operations/files.rst.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,9 @@ Generate a template using jinja2 and write it to the remote system.
683683
a dict with arguments that will be passed as keyword args to the jinja2
684684
`Environment() <https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment>`_.
685685

686+
The ``host``, ``state``, and ``inventory`` objects will be automatically passed to the template
687+
if not set explicitly.
688+
686689
Notes:
687690
Common convention is to store templates in a "templates" directory and
688691
have a filename suffix with '.j2' (for jinja2).
@@ -740,6 +743,21 @@ Notes:
740743
foo_dict=foo_dict,
741744
foo_list=foo_list
742745
)
746+
747+
# Example showing how to use host and inventory in a template file.
748+
template = StringIO("""
749+
name: "{{ host.name }}"
750+
list_contents:
751+
{% for entry in inventory.groups.my_servers %}
752+
- "{{ entry }}"
753+
{% endfor %}
754+
""")
755+
756+
files.template(
757+
name="Create a templated file",
758+
src=template,
759+
dest="/tmp/foo.yml"
760+
)
743761
Note:
744762
This operation also inherits all :doc:`global arguments </arguments>`.
745763

en/next/operations/files.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ <h1>Files Operations<a class="headerlink" href="#files-operations" title="Permal
784784
<dt><code class="docutils literal notranslate"><span class="pre">jinja_env_kwargs</span></code>:</dt><dd>To have more control over how jinja2 renders your template, you can pass
785785
a dict with arguments that will be passed as keyword args to the jinja2
786786
<a class="reference external" href="https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment">Environment()</a>.</dd>
787+
</dl>
788+
<p>The <code class="docutils literal notranslate"><span class="pre">host</span></code>, <code class="docutils literal notranslate"><span class="pre">state</span></code>, and <code class="docutils literal notranslate"><span class="pre">inventory</span></code> objects will be automatically passed to the template
789+
if not set explicitly.</p>
790+
<dl class="docutils">
787791
<dt>Notes:</dt><dd><p>Common convention is to store templates in a “templates” directory and
788792
have a filename suffix with ‘.j2’ (for jinja2).</p>
789793
<p>For information on the template syntax, see
@@ -837,6 +841,21 @@ <h1>Files Operations<a class="headerlink" href="#files-operations" title="Permal
837841
<span class="n">foo_dict</span><span class="o">=</span><span class="n">foo_dict</span><span class="p">,</span>
838842
<span class="n">foo_list</span><span class="o">=</span><span class="n">foo_list</span>
839843
<span class="p">)</span>
844+
845+
<span class="c1"># Example showing how to use host and inventory in a template file.</span>
846+
<span class="n">template</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
847+
<span class="s2">name: &quot;{{ host.name }}&quot;</span>
848+
<span class="s2">list_contents:</span>
849+
<span class="s2">{</span><span class="si">% f</span><span class="s2">or entry in inventory.groups.my_servers %}</span>
850+
<span class="s2"> - &quot;{{ entry }}&quot;</span>
851+
<span class="s2">{</span><span class="si">% e</span><span class="s2">ndfor %}</span>
852+
<span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>
853+
854+
<span class="n">files</span><span class="o">.</span><span class="n">template</span><span class="p">(</span>
855+
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;Create a templated file&quot;</span><span class="p">,</span>
856+
<span class="n">src</span><span class="o">=</span><span class="n">template</span><span class="p">,</span>
857+
<span class="n">dest</span><span class="o">=</span><span class="s2">&quot;/tmp/foo.yml&quot;</span>
858+
<span class="p">)</span>
840859
</pre></div>
841860
</div>
842861
<dl class="docutils">

en/next/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)