Ansible 2.3 create new group on a host fails.

481 views
Skip to first unread message

NixGeek

unread,
Jul 15, 2017, 12:18:01 PM7/15/17
to Ansible Project
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


============================================================

What gives? any ideas.  I've searched for an answer found didly squat.  Nothing really about group ansible module.


Andreas Olsson

unread,
Jul 15, 2017, 12:34:48 PM7/15/17
to ansible...@googlegroups.com
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

NixGeek

unread,
Jul 15, 2017, 2:04:03 PM7/15/17
to Ansible Project

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

Thank you for helping me.

Andreas Olsson

unread,
Jul 15, 2017, 2:42:02 PM7/15/17
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages