Changing Nodegrid User Password Using Ansible
  • 02 Jan 2025
  • 1 Minute to read
  • Dark
    Light
  • PDF

Changing Nodegrid User Password Using Ansible

  • Dark
    Light
  • PDF

Article summary

Changing Nodegrid User Password Using Ansible

This section provides information on how to change the Nodegrid user password using Ansible:

  • Changing user password in Nodegrid 6.0.13 or earlier versions

  • Changing user password in Nodegrid 6.0.15 or later versions

Changing user password in Nodegrid 6.0.13 or earlier versions

To change user password in Nodegrid 6.0.13 or earlier versions, follow these steps. These Nodegrid versions use Ansible with version 2.9.18.

- name: Change user password at localhost
  hosts: 127.0.0.1
  connection: local
  vars:
    username: 'admin'
    raw_password: '<user_password>'

  tasks:

    - name: Change password hash
      user: name={{ username }} password={{ raw_password|password_hash('sha512') }} update_password=always

Changing user password in Nodegrid 6.0.15 or later versions

To change user passwords in Nodegrid 6.0.15 or later versions, follow the steps provided in this section. These Nodegrid versions use Ansible with version 2.17.1.

Note

The passlib library used for user password hashing is an optional dependency in newer Ansible versions such as 2.17.1. Hence, the Ansible filter password_hash() will fail with an error. Refer to the information in this section on how to change user password with alternate methods.

The user passwords can be updated in one of the following ways:

  • Option 1: Change the way password_hash is generated using the OpenSSL command instead.

Or

  • Option 2: Install the passlib.

Option 1: Upgrade playbook. Change the way how to generate the password_hash

- name: Change user password at localhost
  hosts: 127.0.0.1
  connection: local
  vars:
    username: 'admin'
    raw_password: '<user_password>'

  tasks:

    - name: Generate password hash
      shell: openssl passwd -6 -salt xyz {{ raw_password }}
      register: password_hash

    - name: Change password
      user: name={{ username }} password={{ password_hash.stdout }} update_password=always

Option 2: You can use Ansible filter password_hash(‘sha512’) to generate the  user password, however you need to install the passlib

Follow these steps:

  1. Add the library to the Nodegrid.

  2. Install the passlib manually with the ansible user:

    # install the passlib    
    admin@nodegrid /]# shell sudo su - ansible    
    ansible@nodegrid:~$ pip3 install passlib
  3. Change the user password.


Was this article helpful?

ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence