Interview Prep/Ansible/Security: Vault, Become and Compliance

You must rotate the SSH key used by Ansible across all hosts without losing access.

AdvancedScenarioSecurity: Vault, Become and Compliance
Answer

Situation read → Key rotation with rollback safety.

What I'd do →

  1. Add the new public key (keep the old one).
  2. Verify login with the new key on every host.
  3. Switch the controller/AWX credential.
  4. Remove the old key.
- ansible.posix.authorized_key:
    user: ansible
    key: "{{ lookup('file', 'new_ansible.pub') }}"
    state: present
# later
- ansible.posix.authorized_key:
    user: ansible
    key: "{{ lookup('file', 'old_ansible.pub') }}"
    state: absent

Why → Overlap prevents lockouts.

Interview tip → Use exclusive: true only after you are sure.

All Ansible questions Roadmap: Ansible

More on Security: Vault, Become and Compliance