Created
April 11, 2023 14:10
-
-
Save zeitounator/7051e6e3c53dd26b4022b6ce0ac43b9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
├── inventories | |
│ └── demo | |
│ ├── group_vars | |
│ │ └── my_group.yml | |
│ └── hosts.yml | |
├── playbook.yml | |
└── templates | |
└── my_template.html.j2 | |
4 directories, 4 files | |
$ cat inventories/demo/hosts.yml | |
my_group: | |
hosts: | |
host1: | |
$ cat inventories/demo/group_vars/my_group.yml | |
--- | |
# Fake to localhost for this example | |
ansible_connection: local | |
# I don't know where those are set in your example | |
serverName_CN1: server1.local | |
serverName_CN2: server2.local | |
href_CN1: 'https://{{ serverName_CN1 }}' | |
href_CN2: 'https://{{ serverName_CN2 }}' | |
$ cat templates/my_template.html.j2 | |
<p> | |
Try:<br> | |
<a href="{{ href_CN1 }}">{{ serverName_CN1 }}</a><br> | |
<a href="{{ href_CN2 }}">{{ serverName_CN2 }}</a><br> | |
</p> | |
$ cat playbook.yml | |
--- | |
- hosts: my_group | |
gather_facts: false | |
tasks: | |
- ansible.builtin.template: | |
src: my_template.html.j2 | |
dest: /tmp/result_{{ inventory_hostname }}.html | |
$ ansible-playbook -i inventories/demo/ playbook.yml | |
PLAY [my_group] ************************************************************************************************************************************************************************************************************************ | |
TASK [ansible.builtin.template] ******************************************************************************************************************************************************************************************************** | |
changed: [host1] | |
PLAY RECAP ***************************************************************************************************************************************************************************************************************************** | |
host1 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 | |
$ cat /tmp/result_host1.html | |
<p> | |
Try:<br> | |
<a href="https://server1.local">server1.local</a><br> | |
<a href="https://server2.local">server2.local</a><br> | |
</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment