-
Notifications
You must be signed in to change notification settings - Fork 0
Home
IN today's rapidly evolving technological landscape, managing security and efficiency are paramount concerns for organizations with fleets of embedded Linux devices. Regularly updating passwords across multiple devices, while ensuring convenience and reliability, can be a complex task. In this blog post, we'll explore how I leveraged the power of Ansible to create an interactive playbook that changes passwords on multiple embedded Linux machines simultaneously. Understanding Ansible's Power Ansible, a leading open-source automation tool, simplifies IT configuration management, application deployment, and task automation. It's particularly suited for managing distributed systems and network devices due to its declarative nature and seamless remote communication. Prerequisites Before we delve into the Ansible playbook creation, ensure you have the following prerequisites: Ansible Installed: Confirm Ansible is installed on your control machine. SSH Access: You must have SSH access to the embedded Linux machines; Ansible employs SSH for remote communication.
Crafting the Interactive Ansible Playbook Here's where the magic happens. We're delving into crafting an Ansible playbook that goes beyond the basics. We'll structure this playbook with custom roles and tasks for a more organized and modular approach. Navigating Through the Playbook Let's break down the playbook piece by piece, diving into each role and its significance: 1.Role: Setting Up Connection Our playbook opens with the foundation - the connection setup. We configure the playbook to establish an SSH connection to the target hosts. This communication method is ideal for securely managing remote Linux systems. 2. Role: Becoming Root The become role steps into the scene next. By toggling become: yes, we're granting tasks the necessary elevated privileges. This is essential for seamless execution of tasks requiring administrative access. The become_method specifies how we escalate these privileges; in our playbook, it's su. 3. Role: Gathering User Input As interactivity takes center stage, the vars_prompt role comes into play. It prompts users to provide the username for which they intend to change the password. The private: no attribute ensures transparency, while the default attribute serves as a fallback value. 4. Role: Checking User Existence In a logical progression, our playbook verifies the user's existence. This step prevents unnecessary actions on non-existent users. The getent module queries the system's user database, with results stored in the user_exists variable. 5. Role: Changing Password Finally, the grand finale - changing the password. Through the ansible.builtin.user module, we alter the user's password. The name attribute receives the username from user input. The password attribute leverages the SHA-512 algorithm for hashing the new password, ensuring robust security. Launching the Playbook To set this playbook in motion, follow these steps: Open your terminal and navigate to the directory containing the playbook. Execute the playbook using this command: $ ansible-playbook -i inventory playbook.yml -e "hostlist=linux_host" "-u=root" -k -K The playbook will connect to the designated devices, interactively prompt you for the username, and then proceed to securely update the password.
Below are explication of defined tasks used in Ansible playbooks. -e EXTRA_VARS, - extra-vars EXTRA_VARS set additional variables as key=value or YAML/JSON, if filename prepend with -k, - ask-pass ask for connection password -K, - ask-become-pass ask for privilege escalation password Connection Options: control as whom and how to connect to hosts -u REMOTE_USER, - user REMOTE_USER connect as this user (default=None)