# Legal Ansible Syntax/Structure?

**URL:** <https://forum.ansible.com/t/legal-ansible-syntax-structure/44585>\
**Category:** Get Help\
**Created:** [September 30, 2025, 10:51am UTC](https://forum.ansible.com/t/legal-ansible-syntax-structure/44585 "2025-09-30T10:51:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dulux-Oz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulux-oz/32/9047_2.png) [@Dulux-Oz](https://forum.ansible.com/u/Dulux-Oz)\
**Post date:** [September 30, 2025, 10:51am UTC](https://forum.ansible.com/t/legal-ansible-syntax-structure/44585/1 "2025-09-30T10:51:53Z")

</div>

Hey All,

Is the following structure ansible-legal? If not, what structure should I use to make it ansible-legal?

```auto
- block:
  - name: Create The Base SQL Mount Point
    ansible.builtin.file:
      path: "/database"
      owner: root
      group: database_accounts
      mode: "0770"
      state: directory

  - name: Create The {{item}} Mount Point
    ansible.builtin.file:
      path: "/database/{{ansible_hostname}}_{{item}}"
      owner: root
      group: database_accounts
      mode: "0770"
      state: directory

  - name: Copy The {{item}} Mount Point File
    ansible.builtin.template:
      src: etc.systemd.system.database.mount.j2
      dest: /etc/systemd/system/database-{{ansible_hostname}}_{{item}}.mount
      owner: root
      group: root
      mode: "0644"
  when: ansible_hostname == groups.database_{{item}}
  notify: Reload The SystemD Daemon
  with_items:
    - firebird
    - mariadb
    - postgresql

```

What I am trying to achieve is to have a single “task/template set” which will create the appropriate mount point (FTR: on a shared Ceph file system share) depending upon which Inventory Group the server belongs to (eg):

Inventory File:

```auto
[database_firebird]
host1
testhost
[database_mariadb]
host3
testhost
[database_postgresql]
host2
testhost

```

Results:

```auto
host1:/database/host1_firebird
host2:/database/host2_postgresql
host3:/database/host3_mariadb
testhost:/database/testhost_firebird
testhost:/database/testhost_mariadb
testhost:/database/testhost_postgresql

```

This should (I hope) be clear from the above code, but… if its not, then I’m probbaly doing something wrong (which I am anyway because by block doesn’t work) ☹

Thanks in advance for the help

Cheers

Dulux\_Oz

---

<div class="post-metadata">

**Author:** ![mkrizek](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mkrizek/32/2055_2.png) [@mkrizek](https://forum.ansible.com/u/mkrizek)\
**Post date:** [September 30, 2025, 11:54am UTC](https://forum.ansible.com/t/legal-ansible-syntax-structure/44585/2 "2025-09-30T11:54:34Z")

</div>

You cannot loop (`with_items`) over a block. Put the tasks from within the block into a separate file and loop over `include_tasks` including that file.

---

<div class="post-metadata">

**Author:** ![Dulux-Oz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulux-oz/32/9047_2.png) [@Dulux-Oz](https://forum.ansible.com/u/Dulux-Oz)\
**Post date:** [October 1, 2025, 7:50am UTC](https://forum.ansible.com/t/legal-ansible-syntax-structure/44585/3 "2025-10-01T07:50:08Z")

</div>

Thanks @mkrizek

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 31, 2025, 7:50am UTC](https://forum.ansible.com/t/legal-ansible-syntax-structure/44585/4 "2025-10-31T07:50:36Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
