thanks for ur advice,  i have aix and linux,   i wrote the playbook based on ur 
reply,  it works ,  but i think it's too long, is there a better way to rewrite 
this ?

---
- name: test
  hosts: all
  gather_facts: true

  tasks:
   - name: Get information about the user for linux
     getent:
       key=foo
       database=passwd
       fail_key=false
     register: user_info_linux
     when: ansible_system == 'Linux'
   - debug: var=user_info_linux

   - name: Get information about the user for aix
     command: "lsuser foo"
     ignore_errors: yes
     register: user_info_aix
     when: ansible_system == 'AIX'
   - debug: var=user_info_aix

   - name: change pwd for linux
     command: uname -a
     when: ansible_system == 'Linux' and 
user_info_linux.ansible_facts.getent_passwd.foo != None

   - name: change pwd for aix
     command: uname -a
     when: ansible_system == 'AIX' and user_info_aix.stdout != ""





[email protected]
 
From: Kai Stian Olstad
Date: 2016-09-30 19:53
To: ansible-project
Subject: Re: [ansible-project] Re: Re: ansible user module change passwd
On 30.09.2016 11:50, [email protected] wrote:
> i tried,  the playbook still creates the user if  user not exists on
> the remote hosts ;
 
You'll need to add a test to check if the user exist and use a when on 
the update password task.
 
 
> ---
> - hosts: localhost
>   remote_user: root
>   become: yes
>   gather_facts: yes
>   vars:
>     user_name: youruser
> 
>   vars_prompt:
>     - name: "new_password"
>       prompt: "Enter New Password"
>       private: yes
>       encrypt: "md5_crypt"
>       confirm: yes
>       salt_size: 7
> 
>   tasks:
>     - name: Change password of existing user
>       user: name={{user_name}} update_password=always 
> password={{new_password}}
> 
 
tasks:
   - name: Get information about the user
     getent:
       key={{user_name}}
       database=passwd
       fail_key=false
 
   - name: Change password of existing user
     user:
       name={{user_name}}
       update_password=always
       password={{new_password}}
     when: getent_passwd[user_name] != None
 
 
-- 
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/100af417a6c3674c2956c073c0a603e1%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

-- 
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/2016100110242494832424%40foxmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to