EX294 3.1: Preparing managed nodes
Bootstrap an automation user on every managed node with one playbook, run it again without changes, and reach a node by address.
Before you start
This VM is the control node. The lab creates the user greg (password
Lab-Pass-1), who has no SSH key yet, and installs ansible-core. Work as
greg, in /home/greg/ansible: its ansible.cfg reads the inventory
inventory, logs in as devops and becomes root.
The managed nodes node1 (10.99.1.11) and node2 (10.99.1.12) are
AlmaLinux 10 containers with their own users and packages, reached over
SSH by name. On each, root and ansible have the password Lab-Pass-1;
ansible is in wheel, so sudo asks for that password. Nothing else is
set up there. For a root shell on a node, sudo podman exec -it node1 bash.
Tasks
- As greg, write
/home/greg/ansible/bootstrap.ymland run it once with-k, so that every managed node has the userdevopswith a hashed password, passwordless sudo, and greg's public key. Thenansible all -m pingworks without-k, andansible all -a idshowsuid=0(root). - Make a second run of
bootstrap.ymlreportchanged=0on every node. - Point one inventory host at an address instead of a name with
ansible_host, soansible HOST -m pingreaches it.
Hints
ssh-keygen -t ed25519;-kneedssshpasson the control node.remote_user: ansiblewithbecome: trueneeds-Ktoo; withremote_user: root, leave outbecome.password_hash('sha512'),update_password: on_create, a sudoers drop-in withvalidate: /usr/sbin/visudo -cf %s.ansible.posix.authorized_keyneedsansible-galaxy collection install ansible.posix;ansible.builtin.fileandlineinfiledo the same job.ansible-inventory --listshows what Ansible makes of the inventory.