Thank you Kai, you are always helpful

On Friday, March 2, 2018 at 1:39:07 PM UTC-7, Kai Stian Olstad wrote:
>
> On Friday, 2 March 2018 21.17.16 CET John Harmon wrote: 
> > I don't see a way to do this with ansible, but perhaps I am missing 
> > something.  I have a need to change the uid/gid of users/groups on a 
> bunch 
> > of servers; however, I don't wish to create the user/group if it is 
> > missing, I just want to modify it if it exists.  The following creates 
> the 
> > users/groups.  The only state options available are present and absent. 
>  I 
> > need something like, "if present".  I could script it, but I am looking 
> to 
> > stick with the ansible stuff if possible.  Any thoughts? 
> > 
> > - name: Backup /etc/passwd,group files 
> >   copy: 
> >     src: "{{ item.src }}" 
> >     dest: "{{ item.dest }}.{{ ansible_date_time.date }}" 
> >   with_items: 
> >     - { src: "/etc/passwd", dest: "/etc/passwd.bak" } 
> >     - { src: "/etc/group", dest: "/etc/group.bak" } 
> > 
> > - name: Set group uids/gids 
> >   group: 
> >     name: "{{ item.name  }}" 
> >     gid: "{{ item.gid  }}" 
> >   with_items: 
> >     - { name: "gomgroup", gid: "2000" } 
> >     - { name: "pyle", gid: "2001" } 
> > 
> > - name: Set user uids/gids 
> >   user: 
> >     name: "{{ item.name  }}" 
> >     uid: "{{ item.uid  }}" 
> >     group: "{{ item.group }}" 
> >   with_items: 
> >     - { name: "gomer", uid: "2000", group: "gomgroup" } 
> >     - { name: "pyle", uid: "2001", group: "pyle" } 
>
> Not tested, but something like this should work 
>
> - getent: 
>     database: passwd 
> - getent: 
>     database: group 
>
> - name: Set group uids/gids 
>   group: 
>     name: "{{ item.name  }}" 
>     gid: "{{ item.gid  }}" 
>   when: getent_group[item.name] is defined 
>   with_items: 
>     - { name: "gomgroup", gid: "2000" } 
>     - { name: "pyle", gid: "2001" } 
>
> And for the uid you need to add 
>   when: getent_passwd[item.name] is defined 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/1e5fc1e0-af66-485e-b8e6-8dbac8e11155%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to