⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Ansible Automation Interview Questions Scenario 13 of 15 in Ansible Automation
Senior DevOps / SRE [L2] Ansible Security & Privilege Escalation Infrastructure Triage [L2]
🎯 Target Role / Context: Senior DevOps / SRE Scenario #13 · Privilege Escalation & Auth

Q: Tasks requiring sudo are hanging indefinitely on remote Debian servers during non-interactive automated pipeline runs. What is the root cause, and how do you configure passwordless sudo, --ask-become-pass, and ansible.cfg timeouts?

Non-interactive CI/CD runs hang when sudo prompts for passwords without a TTY. Configure NOPASSWD in sudoers.d, verify become_user/become_method, and adjust connect/command timeouts in ansible.cfg.

#Ansible #Privilege Escalation #Sudo #Become #Security
🎙️ Candidate Opening & Architectural Context
""When running Ansible in automated headless pipelines like Jenkins or GitHub Actions, interactive terminal prompts cannot be fulfilled. If sudo requires a password or pty allocation, tasks hang until CI timeouts abort the build. I resolve this by auditing sudoers NOPASSWD policies, become configuration, and timeout settings.""
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

1️⃣

Diagnose Non-Interactive Sudo Prompts

When become: true is executed, Ansible issues sudo -u root .... In a non-interactive CI runner without a pseudo-terminal (TTY), if the remote sudoers file requires a password, the process hangs waiting for stdin that never arrives.

  • Missing TTY / Prompt Hang: Remote system waits for password entry on stdin.
  • requiretty Directive: In older RHEL/CentOS systems, Defaults requiretty prevents execution without an interactive terminal.
2️⃣

Configure Non-Interactive Sudoers Guardrails

Provision a secure, isolated drop-in sudoers file for the Ansible automation service account:

  • Create /etc/sudoers.d/ansible-deploy with permissions 0440.
  • Declare: ansible ALL=(ALL) NOPASSWD: ALL
  • Validate syntax before saving using visudo -cf /etc/sudoers.d/ansible-deploy to prevent syntax lockouts.
Advertisement
3️⃣

Tune Become Parameters in ansible.cfg

Configure explicit escalation parameters in the controller configuration:

  • [privilege_escalation]
    become = True
    become_method = sudo
    become_user = root
    become_ask_pass = False
  • For local debugging: pass -K or --ask-become-pass to provide password manually.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Automated headless pipelines require passwordless sudo (NOPASSWD) in /etc/sudoers.d/ and become_ask_pass = False. Always validate drop-in sudoers configurations with visudo -cf to avoid catastrophic administrative lockouts."
⚡ 60-Second Elevator Pitch Talking Points
  • Ansible hangs in CI/CD when sudo prompts for passwords without an active interactive TTY.
  • Configure NOPASSWD for the dedicated Ansible service user in a dedicated drop-in file: /etc/sudoers.d/ansible.
  • Always validate sudoers syntax using 'visudo -cf /etc/sudoers.d/ansible' to avoid locking out root access.
  • Set 'become_ask_pass = False' and 'become_method = sudo' in the [privilege_escalation] section of ansible.cfg.
  • Remove legacy 'Defaults requiretty' directives from sudoers on enterprise Linux distributions.
  • Use '-b -K' (--ask-become-pass) only when executing playbooks manually from local workstations.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Editing /etc/sudoers directly instead of using /etc/sudoers.d/ drop-in files Package updates overwrite /etc/sudoers, and syntax mistakes lock all administrators out of sudo.
  2. Passing plaintext sudo passwords via extra vars (-e 'ansible_sudo_pass=...') Exposes administrative credentials in process tables (ps aux) and shell history.
  3. Enabling become: true globally on the entire playbook Violates least-privilege principles; declare become only on specific tasks requiring elevated root privileges.
Advertisement
Want more Ansible Automation scenarios?
Explore our complete collection of scenario-based Ansible Automation interview runbooks.
Browse All Ansible Automation Questions →