Hey all,
I'm hoping to use Ansible playbooks to automate a few tasks on my home network. My problem is that I use 2FA for authentication on all of my servers (using Yubikey). I'm quite happy to use key-based authentication for logging on to the servers, but I'd like to still require a one-time-password (OTP) to be entered for running privileged commands with sudo.
If I'm running commands with sudo on a server from the shell, sudo only prompts me the first time for a password / OTP value, after that it will be cached and I won't need to enter it for subsequent commands. Ansible playbooks, from what I can see, are attempting to use the sudo password for every task, which won't work because the OTP value can only be used once (by design).
---
- name: testing
sudo: yes
gather_facts: false
tasks:
- name: tail /var/log/messages
action: command tail -n 5 /var/log/messages
- name: tail /var/log/secure
action: command tail -n 5 /var/log/secure
In the above example, the first task would run using the provided sudo password (a value generated by pressing my Yubikey hardware token), however, any subsequent tasks will fail as the OTP value can only be used once.
If there's no way to make Ansible cache sudo access, then I'm guessing I'll have to use password-less sudo access for various tasks that I want to run in my playbooks? I'm definitely open to suggestions from others that might be using Ansible to manage systems requiring 2FA.
-
Bowen