# Change password using script

**URL:** <https://forum.ansible.com/t/change-password-using-script/29563>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [January 29, 2019, 4:26pm UTC](https://forum.ansible.com/t/change-password-using-script/29563 "2019-01-29T16:26:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mboncalo](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mboncalo](https://forum.ansible.com/u/mboncalo)\
**Post date:** [January 29, 2019, 4:26pm UTC](https://forum.ansible.com/t/change-password-using-script/29563/1 "2019-01-29T16:26:42Z")

</div>

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  
&nbsp;&nbsp;remote\_user: root  
&nbsp;&nbsp;hosts: "{{ hosts }}"

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: Password change Linux  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: root  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update\_password: always  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: "{{ admin\_password | password\_hash('sha512') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: /bin/bash

&nbsp;&nbsp;&nbsp;&nbsp;- name: Copy pw change script AIX  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /root/docker/centos7-ansible/chpas.sh  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/chpas.sh  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mode: 0777  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: script\_copy  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: ansible\_distribution == 'AIX'

&nbsp;&nbsp;&nbsp;&nbsp;- name: Execute pw change AIX script  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: /tmp/chpas.sh root "{{ admin\_password }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: (ansible\_distribution == 'AIX') and  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(script\_copy.rc == 1)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: script\_execute

&nbsp;&nbsp;&nbsp;&nbsp;- name: Clear files  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: '/tmp/chpas.sh'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: absent  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: (ansible\_distribution == 'AIX') and  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(script\_execute.rc== 1)

the error is :

TASK [Gathering Facts]

> **(attachments)**
>
> [chpass.yml](https://forum.ansible.com/uploads/short-url/hUVEL8Is4YplUKonR4yketkvqOa.yml) (895 Bytes)

---

<div class="post-metadata">

**Author:** ![mboncalo](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mboncalo](https://forum.ansible.com/u/mboncalo)\
**Post date:** [January 29, 2019, 6:32pm UTC](https://forum.ansible.com/t/change-password-using-script/29563/2 "2019-01-29T18:32:21Z")

</div>

Issue solved, used "is succeeded" for validation instead of rc == 1

---

<div class="post-metadata">

**Author:** ![mboncalo](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mboncalo](https://forum.ansible.com/u/mboncalo)\
**Post date:** [January 29, 2019, 6:33pm UTC](https://forum.ansible.com/t/change-password-using-script/29563/3 "2019-01-29T18:33:17Z")

</div>

Still could use if i found out what's wrong with using rc since the  
syntax is the same as on ansible website

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 29, 2019, 6:44pm UTC](https://forum.ansible.com/t/change-password-using-script/29563/4 "2019-01-29T18:44:04Z")

</div>

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](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\>

---

<div class="post-metadata">

**Author:** ![mboncalo](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mboncalo](https://forum.ansible.com/u/mboncalo)\
**Post date:** [January 29, 2019, 7:32pm UTC](https://forum.ansible.com/t/change-password-using-script/29563/5 "2019-01-29T19:32:47Z")

</div>

Thanks Kai, I searched for more information on rc but the  
documentation is poor. Thank you for the information!
