--- # State the role must correct: a stale user with a home (state absent removes # it), and an existing user holding an extra key (authoritative mode drops it). - name: Prepare hosts: all gather_facts: false tasks: - name: Create the user the role will remove ansible.builtin.user: name: um-olduser shell: /bin/bash create_home: true - name: Create the additional user with an extra key already planted ansible.builtin.user: name: um-alice shell: /bin/sh create_home: true - name: Create alice's .ssh directory ansible.builtin.file: path: /home/um-alice/.ssh state: directory owner: um-alice group: um-alice mode: "0700" - name: Plant an extra key that authoritative mode must remove ansible.builtin.copy: content: "{{ user_management_test_admin_key | regex_replace('molecule-test$', 'rogue-extra') }}\n" dest: /home/um-alice/.ssh/authorized_keys owner: um-alice group: um-alice mode: "0600" # user_management_lock_root_password: root starts with an unlocked password field (the image # ships "*", which already counts as unusable but does not start with "!") and a key the lock # must leave alone. The value is a placeholder, not a hash: nothing can log in with it. - name: Give root an unlocked password field ansible.builtin.user: name: root password: molecule-unlocked-placeholder update_password: always - name: Create root's .ssh directory ansible.builtin.file: path: /root/.ssh state: directory owner: root group: root mode: "0700" - name: Plant a key in root's authorized_keys that the lock must not touch ansible.builtin.copy: content: "{{ user_management_test_admin_key | regex_replace('molecule-test$', 'root-key') }}\n" dest: /root/.ssh/authorized_keys owner: root group: root mode: "0600"