Operations 3 min read

Using Ansible Playbook to Change the Root Password on Multiple Linux Servers

This guide explains how to configure Ansible inventory, write a YAML playbook that updates the root password on two servers, execute the playbook, and verify the password change through SSH login, illustrating a flexible automation workflow for multi‑host deployments.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Using Ansible Playbook to Change the Root Password on Multiple Linux Servers

Playbook is a mode of using Ansible that is more powerful and flexible than the command‑line interface; it is a simple configuration‑management and multi‑host deployment system described in YAML.

1. Server hostnames

Server 1: 192.168.20.40 (hostname docker02 ) Server 2: 192.168.20.39 (hostname slavedb )

2. Ansible inventory configuration

# /etc/ansible/hosts
[all]
k8s-master ansible_ssh_host=192.168.20.40
k8s-node3  ansible_ssh_host=192.168.20.39

3. Create the playbook (passwd.yml)

---
- hosts: all
  tasks:
    - name: change passwd
      user:
        name: {{ item.user }}
        password: {{ item.password | password_hash('sha512') }}
        update_password: always
      with_items:
        - { user: 'root', password: '123456' }
      register: result
    - debug: var=result

4. Run the playbook

# ansible-playbook passwd.yml

The execution returns a result showing the user root with the hashed password (field password: NOT_LOGGING_PASSWORD ) and other attributes such as uid: 0 , shell: /bin/bash , etc.

5. Verify the password change

After the playbook finishes, SSH into the server (e.g., ssh [email protected] ) and confirm that the new password is effective. The log shows a successful connection and the last login information.

Images in the original article illustrate the inventory file, playbook content, execution output, and SSH login screen.

automationConfiguration ManagementLinuxAnsibleplaybook
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.