thanks, my final playbook comes to this, works pretty well, problem solved!
---
- hosts: all
gather_facts: false
vars:
- usernames: "{{ user_name_lists}}"
tasks:
- name: GetUserInfo
shell: egrep "^{{ item }}:" /etc/passwd
ignore_errors: yes
with_items:
- "{{ usernames }}"
register: user_info
- name: ChangeUserPassord
user: name="{{ item.item }}" password="{{ new_password }}"
update_password=always
when: item.rc == 0
with_items: "{{ user_info.results }}"
[email protected]
From: Kai Stian Olstad
Date: 2016-10-01 17:00
To: ansible-project
Subject: Re: [ansible-project] Re: Re: ansible user module change passwd
On 01. okt. 2016 04:24, [email protected] wrote:
>
> 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 ?
In my opinion it's not long, you could but the code in it's one file and
use include if you would like the playbook to have less code.
> ---
> - 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 != ""
The other option is to use grep/egrep on /etc/passwd, the you can use
the same code on AIX and Linux. I think AIX has egrep.
tasks:
- Name get user
shell: egrep "^{{ user }}:" /etc/passwd
register: user_info
- name: Change passwd
command: <whatever to change password>
when: user_info.rc == 0
--
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/6c6b3958-5bed-0478-971c-3f34cb138312%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/2016100308513651487727%40foxmail.com.
For more options, visit https://groups.google.com/d/optout.