Loops Error!!!

[test@chaitanya244411 Playbooks]$ ansible-playbook -s loop.yml

PLAY [appserver] *********************************************************************************************************************************************************************************************************************

TASK [Add a list of user] ************************************************************************************************************************************************************************************************************

failed: [chaitanya244413.mylabserver.com] (item=user1) => {"changed": false, "item": "user1", "msg": "useradd: invalid user name ''\n", "name": "", "rc": 3}

failed: [chaitanya244413.mylabserver.com] (item=user2) => {"changed": false, "item": "user2", "msg": "useradd: invalid user name ''\n", "name": "", "rc": 3}

failed: [chaitanya244413.mylabserver.com] (item=user3) => {"changed": false, "item": "user3", "msg": "useradd: invalid user name ''\n", "name": "", "rc": 3}

to retry, use: --limit @/home/test/Playbooks/loop.retry

PLAY RECAP ***************************************************************************************************************************************************************************************************************************

chaitanya244413.mylabserver.com : ok=0 changed=0 unreachable=0 failed=1

[test@chaitanya244411 Playbooks]$ cat loop.yml

--- #Loop Playbook Example

- hosts: appserver

user: test

become: yes

connection: ssh

gather_facts: no

tasks:

  - name: Add a list of user

     user: name= "{{ item }}" state=present

loop:

  - user1

  - user2

  - user3


  • post-author-pic
    Stosh O
    11-16-2018

    It may just be how the information pasted, but it appears that your loop may not be indented correctly. The loop should be in the same block as the task calling the user module.


      - name: add users
    user: name="{{item}}" state=present
    loop:
    - user1
    - user2
    - user3

    Hope this helps!

  • post-author-pic
    Krishna C
    11-17-2018

    yes, it's just the way that's being posted here. Thank You.

  • post-author-pic
    Krishna C
    11-17-2018

    It worked when I remove the space I had between "name=" and "{{". Thanks for looking into this.

Looking For Team Training?

Learn More