# Yaml confusion with local\_action

**URL:** <https://forum.ansible.com/t/yaml-confusion-with-local-action/39248>\
**Category:** Get Help\
**Tags:** yaml\
**Created:** [December 19, 2024, 6:24am UTC](https://forum.ansible.com/t/yaml-confusion-with-local-action/39248 "2024-12-19T06:24:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![halloleo](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@halloleo](https://forum.ansible.com/u/halloleo)\
**Post date:** [December 19, 2024, 6:24am UTC](https://forum.ansible.com/t/yaml-confusion-with-local-action/39248/1 "2024-12-19T06:24:57Z")

</div>

I needed to add the `local_action` directive to an action, so I tried this:

```auto
    - name: Create unique tempdir path 
      local_action:
        ansible.builtin.tempfile:
          state: directory
          suffix: _sshpub

```

But the YAML parser wasn’t happy with this. Its rather weak error message didn’t give me much clue, so I resorted to ChatGPT + Google. “They” suggested:

```auto
    - name: Create unique tempdir path 
      local_action:
        module: ansible.builtin.tempfile
        state: directory
        suffix: _sshpub
      register: temp_dir

```

This works. – But why does the first version not work? I usually do not write my actions with the explicit `module` specifier (but rather as the action “heading”) , and it feels annoying that in this one situation I have to do use “module:”.

I am confused. I clearly miss something here…

* * *

ps: Bonus question: Is it possible to apply the `local_action` direction to multiple actions (via a `block` construct maybe)? – My AI didn’t think so, but that doesn’t mean too much.

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [December 19, 2024, 7:25am UTC](https://forum.ansible.com/t/yaml-confusion-with-local-action/39248/2 "2024-12-19T07:25:11Z")

</div>

[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_delegation.html#delegating-tasks](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_delegation.html#delegating-tasks)

[https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_blocks.html#grouping-tasks-with-blocks](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_blocks.html#grouping-tasks-with-blocks)

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [December 19, 2024, 2:07pm UTC](https://forum.ansible.com/t/yaml-confusion-with-local-action/39248/3 "2024-12-19T14:07:50Z")

</div>

I personally think it’s better to use the `delegate_to: localhost` parameter than to use `local_action` … for one, just the reading of the playbook is simpler from an indentation perspective…

I think the first block you have didn’t work because of the indentation - with `local_action`, I believe it flattens the indentation of the module parameters. Again, I personally like everything uniform, so I prefer delegate\_to…

So I think this block should work fine as well, and do the same thing:

```auto
- name: Create unique tempdir path 
  delegate_to: localhost
  ansible.builtin.tempfile:
    state: directory
    suffix: _sshpub

```

---

<div class="post-metadata">

**Author:** ![Thulium-Drake](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thulium-drake/32/833_2.png) [@Thulium-Drake](https://forum.ansible.com/u/Thulium-Drake)\
**Post date:** [December 19, 2024, 2:41pm UTC](https://forum.ansible.com/t/yaml-confusion-with-local-action/39248/4 "2024-12-19T14:41:02Z")

</div>

I agree with @jrglynn2’s observation on using `delegate_to`, I never use `local_action`. And when using a block, you can set `delegate_to` on that level to make it apply to all tasks in the block 🙂

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [December 19, 2024, 4:27pm UTC](https://forum.ansible.com/t/yaml-confusion-with-local-action/39248/5 "2024-12-19T16:27:43Z")

</div>

Since `delegate_to: localhost` has already been suggested I’m just going to clarify that `action` and `local_action` do not allow for unknown entries in their args in YAML form only in k=v, which assumes they are the ‘module/action plugin’, so these are all the valid forms:

```yaml
- action:
       module: <action name>
- action: <action name>
- <action name>:

```

Of course, you can substitute `action` for `local_action` in any of these, but what you attempted it just not supported.

---

<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:** [January 18, 2025, 4:28pm UTC](https://forum.ansible.com/t/yaml-confusion-with-local-action/39248/6 "2025-01-18T16:28:07Z")

</div>

Closed on January 18, 2025, 4:28pm UTC

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