小编Lam*_*uré的帖子

Ansible 上的问题

我已经开始了 Ansible 培训。
我有一个非常简单的用例:我正在尝试使用 jinja 模板生成 html 文件。
在这里找到我的 yml 文件:

---

- name: "Generate html file for each host"
  hosts: all
  connection: local
  gather_facts: yes
  vars:
    host_inventory: "localhost"
    inventory_dir: "/home/ansible/Ansible/ch02/var/www/html/inventory"
  tasks:
    - name: "Create template directory"
      file:
        path: "{{playbook_dir}}"
        owner: "ansible"
        group: "ansible"
        mode: "0755"
        state: "directory"
      delegate_to: "{{host_inventory}}"
    - name: "Html file generation"
      template:
        src: "host.html.j2"
        dest: "{{playbook_dir}}/{{inventory_hostname}}.html"
      delegate_to: "{{host_inventory}}"
Run Code Online (Sandbox Code Playgroud)

在这里找到 jinja 文件:

<html>
  <head>
    <title> host {{inventory_hostname}} </title>
  </head>
  <body>
    <p> 
      This host is called {{inventory_hostname}} 
    </p> …
Run Code Online (Sandbox Code Playgroud)

jinja2 ansible

2
推荐指数
1
解决办法
189
查看次数

标签 统计

ansible ×1

jinja2 ×1