I am trying to create an ansible play that
1. Establishes if a user exists on a host and records the stdout as a register variable. Referencing a dict file which contains what users should be on the host. 2. Creates a group for the user which will be created (with data from the dict) if the stdout == 0 3. Creates a user account (with data from the dict) if the stdout == 0 4. Copies over a sudoers.d template for a pre-existing ops group And I saw at https://groups.google.com/forum/#!topic/ansible-project/htHzfr5HzQE that the register is turn into a list when combine in with_items. I can't seem to figure out how to iterate over a register variable list. Essentially, I'd like for my OpsTeam.yaml variables to correlate with the register variables and use that to determine if action should be taken. Note: this play currently does not work Here is my code: --- - name: Deploy Users and Keys hosts: tag_AddUsers_ sudo: yes vars_files: - "OpsTeam.yaml" tasks: - name: establish if user exists shell: /usr/bin/getent passwd {{ item.name }} | /usr/bin/wc -l | tr -d ' ' register: user_exists with_items: users - name: create user group if doesnt already exist command: /usr/sbin/groupadd {{ item.name }} when: user_exists.stdout == 0 with_together: - users - user_exists - name: Add in Ops sudoers.d file template: src=./ops dest=/etc/sudoers.d/ops - name: add users user: name={{ item.name }} createhome=yes group={{ item.name }} groups=ops append=no state=present shell=/bin/bash when: user_exists.stdout == 0 with_together: - users - user_exists Thanks in advance -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/da6cc618-4545-480e-88bb-910cd6aa39ee%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
