Change password using script

18 views
Skip to first unread message

boncalo mihai

unread,
Jan 29, 2019, 11:27:06 AM1/29/19
to ansible...@googlegroups.com
Hi guys,

I kinda feel ashamed asking this kind of questions but I'm currently
still learning Ansible, only started a week ago and I have to complete
this as a part of a personal project that I will present.

I wrote a simple playbook for changing passwords on linux systems,
will have to add module for windows later but now the issue is with
AIX systems.
User module isn't working for AIX, I tried things from internet but no
success so I wrote a script that changes the password on AIX with 2
arguments, user and password---> as a result the password is changed
for that user.
What I have to do in the playbook is to run copy and run this script
on the remote server with the password and user that I give give using
-e when the remote system is AIX:

- name: User configuration
remote_user: root
hosts: "{{ hosts }}"

tasks:
- name: Password change Linux
user:
name: root
state: present
update_password: always
password: "{{ admin_password | password_hash('sha512') }}"
shell: /bin/bash

- name: Copy pw change script AIX
copy:
src: /root/docker/centos7-ansible/chpas.sh
dest: /tmp/chpas.sh
mode: 0777
register: script_copy
when: ansible_distribution == 'AIX'

- name: Execute pw change AIX script
command: /tmp/chpas.sh root "{{ admin_password }}"
when: (ansible_distribution == 'AIX') and
(script_copy.rc == 1)
register: script_execute

- name: Clear files
file:
path: '/tmp/chpas.sh'
state: absent
when: (ansible_distribution == 'AIX') and
(script_execute.rc== 1)


the error is :


TASK [Gathering Facts]
***************************************************************************************************************************************************************************************
ok: [ansible_aix]

TASK [Password change Linux]
*********************************************************************************************************************************************************************************
changed: [ansible_aix] => {"append": false, "changed": true,
"comment": "", "group": 0, "home": "/root", "move_home": false,
"name": "root", "password": "NOT_LOGGING_PASSWORD", "shell":
"/bin/bash", "state": "present", "uid": 0}

TASK [Copy pw change script AIX]
*****************************************************************************************************************************************************************************
ok: [ansible_aix] => {"changed": false, "checksum":
"d434aee957d8a46a41f92f76936ebcf53848dc1b", "dest": "/tmp/chpas.sh",
"gid": 0, "group": "system", "mode": "0777", "owner": "root", "path":
"/tmp/chpas.sh", "size": 458, "state": "file", "uid": 0}

TASK [Execute pw change AIX script]
**************************************************************************************************************************************************************************
fatal: [ansible_aix]: FAILED! => {"msg": "The conditional check
'(ansible_distribution == 'AIX') and (script_copy.rc == 1)' failed.
The error was: error while evaluating conditional
((ansible_distribution == 'AIX') and (script_copy.rc == 1)): 'dict
object' has no attribute 'rc'\n\nThe error appears to have been in
'/root/docker/centos7-ansible/chpass.yml': line 22, column 7, but
may\nbe elsewhere in the file depending on the exact syntax
problem.\n\nThe offending line appears to be:\n\n\n - name: Execute
pw change AIX script\n ^ here\n"}
to retry, use: --limit @/root/docker/centos7-ansible/chpass.retry

PLAY RECAP ***************************************************************************************************************************************************************************************************
ansible_aix : ok=3 changed=1 unreachable=0 failed=1

Attached the yml file since I don't think the code is well aligned after paste.

Thank you very much,
Mihai.
chpass.yml

boncalo mihai

unread,
Jan 29, 2019, 1:32:47 PM1/29/19
to ansible...@googlegroups.com
Issue solved, used "is succeeded" for validation instead of rc == 1

boncalo mihai

unread,
Jan 29, 2019, 1:33:42 PM1/29/19
to ansible...@googlegroups.com
Still could use if i found out what's wrong with using rc since the
syntax is the same as on ansible website

Kai Stian Olstad

unread,
Jan 29, 2019, 1:44:15 PM1/29/19
to ansible...@googlegroups.com
On 29.01.2019 19:33, boncalo mihai wrote:
> Still could use if i found out what's wrong with using rc since the
> syntax is the same as on ansible website

Most modules doesn't return rc and copy is one of them
https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#rc

You can always use this to show what a module is returning.

- debug: var=<variable name>

--
Kai Stian Olstad

boncalo mihai

unread,
Jan 29, 2019, 2:33:15 PM1/29/19
to ansible...@googlegroups.com
Thanks Kai, I searched for more information on rc but the
documentation is poor. Thank you for the information!
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/768dbf84f5b193e900f9555d6db04036%40olstad.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages