# Changing non-ansible user password on remote server

**URL:** <https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510>\
**Category:** Get Help\
**Tags:** ssh, playbook\
**Created:** [October 25, 2024, 1:22pm UTC](https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510 "2024-10-25T13:22:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stipemd](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@stipemd](https://forum.ansible.com/u/stipemd)\
**Post date:** [October 25, 2024, 1:22pm UTC](https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510/1 "2024-10-25T13:22:02Z")

</div>

There exists a service account `srvAdmin` on other Linux hosts which I need to log in as that account and change its password. I can’t set up an ansible service account on all those other hosts since they don’t belong to me.

I have the ansible\_password variable set in my inventory file. I know thats not best practice but I can’t use my ansible service account SSH key in this case.

This is what the inventory file looks like:

```auto
all:
  vars:
    ansible_user: srvAdmin
    ansible_password: password123

```

My goal is to login in to other servers using these credentials.

I need assistance on the playbook aspect:

```auto
- name: Change the srvAdmin password
  hosts: all
  any_errors_fatal: true
  become: false
  vars:
    myuser: "srvAdmin "
    currentPassword: "password123"
    newPassword: "password123abc"

```

Basically I’m not sure of what module to use to change from `currentPassword` to `newPassword`.

I was thinking the `ansible.builtin.shell` module to issue the `passwd` command but I’m not sure on how to:

1. Enter in the value of `currentPassword` once `passwd` gets executed.
2. And similarly enter the `newPassword`.

Thanks for reading

---

<div class="post-metadata">

**Author:** ![anon81884396](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@anon81884396](https://forum.ansible.com/u/anon81884396)\
**Post date:** [October 25, 2024, 2:27pm UTC](https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510/2 "2024-10-25T14:27:41Z")

</div>

[ansible.builtin.user module – Manage user accounts — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html#parameter-password) ?

---

<div class="post-metadata">

**Author:** ![stipemd](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@stipemd](https://forum.ansible.com/u/stipemd)\
**Post date:** [October 25, 2024, 2:41pm UTC](https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510/3 "2024-10-25T14:41:55Z")

</div>

well I also have some odd servers with different operating system such as ADE-OS so I thought shell module would help run into less errors where as I don’t know if user module will cause an error or not.

---

<div class="post-metadata">

**Author:** ![anon81884396](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@anon81884396](https://forum.ansible.com/u/anon81884396)\
**Post date:** [October 25, 2024, 2:58pm UTC](https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510/4 "2024-10-25T14:58:03Z")

</div>

Never heard of that OS. Pick a test system of minimal impact/importance and see if it works.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [October 25, 2024, 8:44pm UTC](https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510/5 "2024-10-25T20:44:17Z")

</div>

ADE-OS will probably not work with `shell` either, only with `raw`, I would look at the cisco collections/modules to see if any support it.

---

<div class="post-metadata">

**Author:** ![stipemd](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@stipemd](https://forum.ansible.com/u/stipemd)\
**Post date:** [October 29, 2024, 5:27pm UTC](https://forum.ansible.com/t/changing-non-ansible-user-password-on-remote-server/10510/6 "2024-10-29T17:27:55Z")

</div>

I’m trying the user module but is there any way I can do it without needing sudo?

I have `become: false` set and get the below message on each server when I run the playbook.

`ansible FAILED! => {"changed": false, "msg": "usermod: Permission denied.\nusermod: cannot lock /etc/passwd; try again later`

If I have `become: true` and run the playbook, then I get the below message which makes sense.  
`"msg": "Missing sudo password"`

playbook

```auto
name: blah
  hosts: all
  any_errors_fatal: true
  become: false

  tasks:
    - name: Change the password for srvAdmin
      ansible.builtin.user:
        name: srvAdmin
        update_password: always
        password: "{{ newPassword|password_hash('sha512') }}"

```

I pass in the value of newPassword via command line var
