# What exactly is the "action" module and how does it work?

**URL:** <https://forum.ansible.com/t/what-exactly-is-the-action-module-and-how-does-it-work/25109>\
**Category:** Ansible Project\
**Created:** [July 27, 2017, 4:42pm UTC](https://forum.ansible.com/t/what-exactly-is-the-action-module-and-how-does-it-work/25109 "2017-07-27T16:42:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Thommen](https://avatars.discourse-cdn.com/v4/letter/f/7feea3/32.png) [@Frank\_Thommen](https://forum.ansible.com/u/Frank_Thommen)\
**Post date:** [July 27, 2017, 4:42pm UTC](https://forum.ansible.com/t/what-exactly-is-the-action-module-and-how-does-it-work/25109/1 "2017-07-27T16:42:27Z")

</div>

Hi,

I was looking for a way to run the distro-dependent package manager w/o too many "when"s and I found this (on [https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing\_packages/#installing-packages](https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing_packages/#installing-packages)):

- name: install basic package  
&nbsp;&nbsp;&nbsp;action: \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }} name=vim state=present update\_cache=yes

However I cannot find this "action" module mentioned anywhere in the whole Ansible documentation and I also don't understand, why the "\>" is needed at that point. Is this an obsolete feature or a very new one, which is not documented yet? What exactly can one do with it?

Cheers  
frank

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 27, 2017, 5:25pm UTC](https://forum.ansible.com/t/what-exactly-is-the-action-module-and-how-does-it-work/25109/2 "2017-07-27T17:25:34Z")

</div>

> Hi,
> 
> I was looking for a way to run the distro-dependent package manager w/o too many "when"s and I found this (on [https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing\_packages/#installing-packages](https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing_packages/#installing-packages)):
> 
> - name: install basic package  
> &nbsp;&nbsp;&nbsp;action: \>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }} name=vim state=present update\_cache=yes
> 
> However I cannot find this "action" module mentioned anywhere in the whole Ansible documentation

[https://docs.ansible.com/ansible/latest/playbooks\_intro.html#tasks-list](https://docs.ansible.com/ansible/latest/playbooks_intro.html#tasks-list)  
[https://docs.ansible.com/ansible/latest/playbooks\_intro.html#action-shorthand](https://docs.ansible.com/ansible/latest/playbooks_intro.html#action-shorthand)

In short, it's an old syntax not encourage used anymore.

> and I also don't understand, why the "\>" is needed at that point.

It's an yaml indicator character, "\>" indicate that the lines can be broken to multiple lines.

> Is this an obsolete feature or a very new one, which is not documented yet? What exactly can one do with it?

I think you need to use action if the module name is a variable as in you example.  
I think these two examples would fail.

&nbsp;&nbsp;&nbsp;- name: install basic package  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }}: name=vim state=present update\_cache=yes

and

&nbsp;&nbsp;&nbsp;- name: install basic package  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }}:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: vim  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update\_cache: yes

---

<div class="post-metadata">

**Author:** ![Frank\_Thommen](https://avatars.discourse-cdn.com/v4/letter/f/7feea3/32.png) [@Frank\_Thommen](https://forum.ansible.com/u/Frank_Thommen)\
**Post date:** [July 27, 2017, 5:41pm UTC](https://forum.ansible.com/t/what-exactly-is-the-action-module-and-how-does-it-work/25109/3 "2017-07-27T17:41:29Z")

</div>

Thanks a lot

> > Hi,
> > 
> > I was looking for a way to run the distro-dependent package manager  
> > w/o too many "when"s and I found this (on  
> > [https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing\_packages/#installing-packages](https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing_packages/#installing-packages)):
> > 
> > - name: install basic package  
> > &nbsp;&nbsp;&nbsp;action: \>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }} name=vim state=present update\_cache=yes
> > 
> > However I cannot find this "action" module mentioned anywhere in the  
> > whole Ansible documentation
> 
> [https://docs.ansible.com/ansible/latest/playbooks\_intro.html#tasks-list](https://docs.ansible.com/ansible/latest/playbooks_intro.html#tasks-list)  
> [https://docs.ansible.com/ansible/latest/playbooks\_intro.html#action-shorthand](https://docs.ansible.com/ansible/latest/playbooks_intro.html#action-shorthand)

Shame on me. I overlooked it in the very basic intro page... :-}

> In short, it's an old syntax not encourage used anymore.
> 
> > and I also don't understand, why the "\>" is needed at that point.
> 
> It's an yaml indicator character, "\>" indicate that the lines can be  
> broken to multiple lines.

Yes, that I know that, but I just don't understand, why

- name: install basic package  
&nbsp;&nbsp;&nbsp;&nbsp;action: {{ ansible\_pkg\_mgr }} name=vim state=present update\_cache=yes

or

- name: install basic package  
&nbsp;&nbsp;&nbsp;&nbsp;action: "{{ ansible\_pkg\_mgr }}" name=vim state=present update\_cache=yes

Wouldn't work (both fail with YAML syntax error)

> > Is this an obsolete feature or a very new one, which is not  
> > documented yet? What exactly can one do with it?
> 
> I think you need to use action if the module name is a variable as in  
> you example.  
> I think these two examples would fail.
> 
> &nbsp;&nbsp;- name: install basic package  
> &nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }}: name=vim state=present update\_cache=yes
> 
> and
> 
> &nbsp;&nbsp;- name: install basic package  
> &nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }}:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: vim  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update\_cache: yes

Indeed they fail, and there doesn't seem to be a useable replacement in the current syntax. ☹

frank

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 27, 2017, 6:11pm UTC](https://forum.ansible.com/t/what-exactly-is-the-action-module-and-how-does-it-work/25109/4 "2017-07-27T18:11:14Z")

</div>

> > > and I also don't understand, why the "\>" is needed at that point.
> > 
> > It's an yaml indicator character, "\>" indicate that the lines can be  
> > broken to multiple lines.
> 
> Yes, that I know that, but I just don't understand, why

It looks nicer and that don't need the quotes perhaps?

> - name: install basic package  
> &nbsp;&nbsp;action: {{ ansible\_pkg\_mgr }} name=vim state=present update\_cache=yes
> 
> or
> 
> - name: install basic package  
> &nbsp;&nbsp;action: "{{ ansible\_pkg\_mgr }}" name=vim state=present update\_cache=yes
> 
> Wouldn't work (both fail with YAML syntax error)

{ it's not allox after the colon and in yaml, if it start with a quote it must end with the same qoute, so this should work.

- name: install basic package  
&nbsp;&nbsp;&nbsp;action: "{{ ansible\_pkg\_mgr }} name=vim state=present pdate\_cache=yes"

> > > Is this an obsolete feature or a very new one, which is not  
> > > documented yet? What exactly can one do with it?
> > 
> > I think you need to use action if the module name is a variable as in  
> > you example.  
> > I think these two examples would fail.
> > 
> > &nbsp;&nbsp;- name: install basic package  
> > &nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }}: name=vim state=present update\_cache=yes
> > 
> > and
> > 
> > &nbsp;&nbsp;- name: install basic package  
> > &nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }}:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: vim  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update\_cache: yes
> 
> Indeed they fail, and there doesn't seem to be a useable replacement in the current syntax. ☹

If you don't need the cache update a module exist, it's called packages.
