LOGBOOK

HELP

Quiz Entry - updated: 2026.11.05

How can a task write an index.html whose text includes the host's own FQDN and IPv4 address, without a template file?

Use ansible.builtin.copy with content: instead of src:, and put facts into the content: {{ ansible_facts['fqdn'] }} and {{ ansible_facts['default_ipv4']['address'] }}. Every host gets a file with its own values.

- name: Create index.html
  ansible.builtin.copy:
    content: >
      {{ ansible_facts['fqdn'] }}
      ({{ ansible_facts['default_ipv4']['address'] }})
      was created by Ansible.
    dest: "{{ web_root }}/index.html"

On a host it produces, for example: web1.example.com (10.176.118.15) was created by Ansible.

Details that make this work:

  • content: writes the given string to dest; no source file is needed. It suits short, generated text. For anything larger, the template module with a Jinja2 file is the better tool.
  • > is YAML's folded block scalar: the three lines are joined into one with spaces, and a single newline is added at the end.
  • The facts were gathered automatically at the start of the play, so the task can use them without any extra step.

Go deeper:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 05, 2026