Ansible (11) template Module

Source: Internet
Author: User

Ansible (11) template Module
Template Module

The template module is involved in the first playbook in the previous section. What is this?
Let's go over what we said on the official website (translated in the general section ):

The template uses the Jinjia2 format as the file template to replace the variables in the document. Every time it is used, it is marked as "changed" by ansible.

It's hard to understand, so let's take a look at the actual example.

Common Parameters
Parameter Name Required? Default Value Option Description
Backup No No Yes/no Create a file backup, including timestamp, for emergency purposes.
Dest Yes The absolute path on the remote node, used to place the template file.
Group No Set the user group to which the template file belongs on the remote node.
Mode No Set the template file permission on the remote node. Similar to LinuxChmodUsage
Owner No Set the user to which the template file on the remote node belongs.
Src Yes The location of the template file of the local Jinjia2 template.
Case
# Set/mytemplates/foo. after entering the parameters, the j2 file is copied to the/etc/file on the remote node. conf, File Permission-related skipped-template: src =/mytemplates/foo. j2 dest =/etc/file. conf owner = bin group = wheel mode = 0644 # same effect as above, different file permission setting methods-template: src =/mytemplates/foo. j2 dest =/etc/file. conf owner = bin group = wheel mode = "u = rw, g = r, o = r"
Detailed description

We can check it here.
The key part of the template file in roles/templates/server. xml is as follows:

 <user username="{{ admin_username }}" password="{{ admin_password }}" roles="manager-gui" />

When this file has not been executed by the templateAdmin_usernameAndAdmin_passwordAll are variable statuses.
When the playbook executes the template, the remote admin_username * andAdmin_passwordThe value corresponding to the variable.

For example:
In the previous Playbook, if we set these two variables in tomcat-servers:

dmin_username: adminadmin_password: adminsecret

Before executing this Playbook, the corresponding template file (commonly known as the template) will be in the local state of {admin_username }}and {admin_password. When Ansible calls the template for execution, Jinjia2 reads the corresponding value from "tomcat-servers" and replaces the variables in the template, copy the file with the variable value replaced to the remote node.

This is the meaning of the template.

Do you understand the convenience of Ansible?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.