Ansible 2.3 create new group on a host fails.

My Ansible version:

ansible-playbook 2.3.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609]

Per the documentation to add a group

# Example group command from Ansible Playbooks
- group:
    name: somegroup
    state: present
My playbook
======================================
---

- hosts: myhosts
  tasks:

- group:
    name: useradmins
    state: present
=======================================

when I run I get errors:

ansible-playbook -v addgroup.yml

Using /etc/ansible/ansible.cfg as config file

ERROR! ‘group’ is not a valid attribute for a Play

The error appears to have been in ‘/etc/ansible/playbooks/addgroup.yml’: line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  • group:
    ^ here

lör 2017-07-15 klockan 09:18 -0700 skrev NixGeek:

My playbook

---

- hosts: myhosts
tasks:

- group:
name: useradmins
state: present

It looks as if you have gotten the indentation wrong. You want the
group creation to be a list item under tasks.

- hosts: myhosts
tasks:
- group:
name: useradmins
state: present

// Andreas

man one reason ansible makes me crazy is the silly indented crap in the playbook.

Thank you for helping me.

lör 2017-07-15 klockan 11:04 -0700 skrev NixGeek:

man one reason ansible makes me crazy is the silly indented crap in
the playbook.

That "silly indented crap" is more formally referred to as YAML. For
better or worse it's fairly commonly used. Investing a bit of time in
understanding YAML will easily pay off in the long run.

Using a text editor with YAML support is also helpful.

// Andreas