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.