Troubleshooting
Realistic Ansible failures with exact error text: likely causes, how to diagnose, how to fix and how to prevent them
Connection and SSH Failures
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q1 UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password)."}
Beginner
UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password)."}Likely causes โ Wrong user, wrong or missing private key, key not in authorized_keys, or the server disallows the auth method.
Diagnose โ
ansible web01 -m ping -vvv
ssh -i ~/.ssh/id_ed25519 -v ec2-user@web01-vvv shows the exact ssh command Ansible built, including -o User= and IdentityFile.
Fix โ Set ansible_user and ansible_ssh_private_key_file in inventory, or pass -u and --private-key. Add the public key to ~/.ssh/authorized_keys with correct permissions (700 on .ssh, 600 on the file).
Prevent โ Standardise one automation user and key per environment, and test with ansible all -m ping in CI.
Q2 UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host 10.0.1.15 port 22: Connection timed out"}
Beginner
UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host 10.0.1.15 port 22: Connection timed out"}Likely causes โ Security group or firewall blocking port 22, host down, wrong IP, or no route (private subnet without bastion).
Diagnose โ
nc -vz 10.0.1.15 22
traceroute -T -p 22 10.0.1.15
ansible-inventory --host web01 | grep ansible_hostFix โ Open TCP 22 from the controller or bastion, correct ansible_host, or add ansible_ssh_common_args: '-o ProxyJump=bastion'.
Prevent โ Keep network access for the control node in IaC, and use dynamic inventory with private IPs.
Q3 UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host web01 port 22: Connection refused"}
Beginner
UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host web01 port 22: Connection refused"}Likely causes โ sshd is not running, listens on another port, or the host is still booting.
Diagnose โ
nc -vz web01 22
ssh -p 2222 user@web01 # test an alternate port
# on the host console: systemctl status sshd; ss -tlnp | grep sshFix โ Start sshd, or set ansible_port in inventory. After provisioning use wait_for_connection or wait_for on port 22.
Prevent โ Add a wait step in provisioning playbooks.
Q4 Host key verification failed. after rebuilding a server
Beginner
Host key verification failed. after rebuilding a serverLikely causes โ The host was recreated with a new host key but known_hosts has the old one.
Diagnose โ ssh-keygen -F web01 and compare the fingerprint.
Fix โ
ssh-keygen -R web01
ssh-keyscan -H web01 >> ~/.ssh/known_hostsFor short-lived hosts: ansible_ssh_common_args: '-o StrictHostKeyChecking=accept-new'.
Prevent โ Prefer accept-new over disabling checks, and publish host keys via SSHFP or your CA. Avoid host_key_checking = False in production.
Q5 The playbook hangs for ever at "Gathering Facts" on one host
Intermediate
Likely causes โ SSH waiting for a prompt (new host key confirmation or password), a slow DNS lookup on the target, sudo prompting for a password, or a broken shell profile printing output.
Diagnose โ
ansible web01 -m setup -vvv
ssh -v web01 trueCheck UseDNS in sshd_config and /etc/profile or .bashrc for interactive commands.
Fix โ Disable UseDNS, make profiles non-interactive ([[ $- == *i* ]] || return), set timeout = 30, and use ansible_ssh_common_args with -o BatchMode=yes.
Prevent โ Use BatchMode and a connect timeout in ansible.cfg.
Q6 Failed to connect to the host via ssh: Too many authentication failures
Intermediate
Failed to connect to the host via ssh: Too many authentication failuresLikely causes โ ssh-agent holds many keys and the server hits MaxAuthTries before reaching the right one.
Diagnose โ ssh-add -l, then ssh -vvv host to see keys offered.
Fix โ
[ssh_connection]
ssh_args = -o IdentitiesOnly=yesand set ansible_ssh_private_key_file explicitly.
Prevent โ Use IdentitiesOnly=yes and one key per environment.
Q7 fatal: [web01]: UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Shared connection to web01 closed."} mid-run
Intermediate
fatal: [web01]: UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Shared connection to web01 closed."} mid-runLikely causes โ The SSH ControlPersist socket is stale, the connection dropped mid-run (NAT idle timeout), or the host rebooted.
Diagnose โ Look for ControlPath sockets in ~/.ansible/cp/ and test ssh -O check host.
Fix โ
rm -rf ~/.ansible/cp/*and set keepalives: ssh_args = -o ServerAliveInterval=30 -o ServerAliveCountMax=5 -o ControlMaster=auto -o ControlPersist=60s.
Prevent โ Use keepalives on long runs, and the reboot module for restarts.
Q8 unix_listener: path "/home/user/.ansible/cp/xxxx.yyyy" too long for Unix domain socket
Intermediate
unix_listener: path "/home/user/.ansible/cp/xxxx.yyyy" too long for Unix domain socketLikely causes โ The ControlPath is longer than the 104-108 byte socket path limit, common with long hostnames or deep home directories.
Diagnose โ Check control_path_dir and the hostnames in use.
Fix โ
[ssh_connection]
control_path_dir = /tmp/.ansible-cp
# or
control_path = %(directory)s/%%CPrevent โ Use the hashed %C token (default in modern versions) and a short directory.
Q9 Failed to connect to the host via ssh: ... Permission denied only when the playbook runs from CI, not from my laptop
Intermediate
Failed to connect to the host via ssh: ... Permission denied only when the playbook runs from CI, not from my laptopLikely causes โ CI runner lacks the key or ssh-agent, key file permissions are too open, or the user name differs.
Diagnose โ
ls -l $KEY_FILE # must be 600
ssh -i $KEY_FILE -o BatchMode=yes -vv user@host trueFix โ Write the key from a secret to a file with chmod 600, and pass --private-key. Set ANSIBLE_REMOTE_USER explicitly.
Prevent โ Use the same container image locally and in CI.
Q10 ERROR! Specified inventory, inventory directory, or script does not exist / [WARNING]: provided hosts list is empty, only localhost is available
Beginner
ERROR! Specified inventory, inventory directory, or script does not exist / [WARNING]: provided hosts list is empty, only localhost is availableLikely causes โ Wrong -i path, wrong working directory, or inventory = missing from ansible.cfg; a trailing comma is needed for a one-off host list.
Diagnose โ
ansible --version | grep 'config file'
ansible-inventory -i inventory.ini --graphFix โ Fix the path, or use -i 'web01,' (with the comma) for a single host.
Prevent โ Set inventory in a checked-in ansible.cfg.
Q11 [WARNING]: Could not match supplied host pattern, ignoring: webservers
Beginner
[WARNING]: Could not match supplied host pattern, ignoring: webserversLikely causes โ Group does not exist in the loaded inventory, typo or case mismatch, or the dynamic inventory returned nothing.
Diagnose โ
ansible-inventory -i inventory --graph
ansible webservers --list-hostsFix โ Correct the group name or fix the inventory source.
Prevent โ In CI run ansible-playbook ... --list-hosts first and fail the job when the host count is zero.
Q12 skipping: no hosts matched and the play does nothing
Beginner
skipping: no hosts matched and the play does nothingLikely causes โ hosts: pattern empty, --limit excludes everything, or the host list resolved to zero because of :& logic.
Diagnose โ ansible-playbook site.yml --list-hosts, then remove --limit to compare.
Fix โ Correct the pattern or limit; remember that a limit pattern can only narrow what the play targets.
Prevent โ Print --list-hosts in pipelines before deploying.
Q13 Timeout (12s) waiting for privilege escalation prompt
Intermediate
Timeout (12s) waiting for privilege escalation promptLikely causes โ sudo is asking for a password in a different form than expected, requiretty is set, a slow PAM or DNS lookup delays the prompt, or become_method does not match the host.
Diagnose โ
ssh host 'sudo -n true'
ansible web01 -b -m ping -vvvCheck /etc/sudoers and /var/log/auth.log.
Fix โ Increase timeout, fix DNS (/etc/hosts with the hostname), set ansible_become_method, or use passwordless sudo for the automation user.
Prevent โ Make sure the hostname resolves locally on every target.
Q14 msg: "Invalid/incorrect password: Sorry, try again." when using -K
Beginner
msg: "Invalid/incorrect password: Sorry, try again." when using -KLikely causes โ Typed the login password instead of the sudo password, the account has no sudo rights, or the password differs per host.
Diagnose โ ssh -t host sudo -v and enter the password manually.
Fix โ Provide the right password via -K or ansible_become_password (vaulted).
Prevent โ Use passwordless sudo with limited commands for the automation account.
Q15 SSH works from the shell but Ansible says UNREACHABLE with Could not resolve hostname
Beginner
UNREACHABLE with Could not resolve hostnameLikely causes โ Inventory name is not resolvable DNS and ansible_host is not set; shell uses ~/.ssh/config aliases but the inventory uses a different name.
Diagnose โ
getent hosts web01
ansible-inventory --host web01 | jq .ansible_hostFix โ Set ansible_host: 10.0.1.15, or add the alias to DNS. Ansible honours ~/.ssh/config too, but only for the name it connects with.
Prevent โ Keep ansible_host in inventory (or compose it dynamically).
Q16 Failed to connect to the host via ssh: Bad owner or permissions on /home/user/.ssh/config
Beginner
Failed to connect to the host via ssh: Bad owner or permissions on /home/user/.ssh/configLikely causes โ SSH rejects config or key files that are group/world writable or owned by someone else.
Diagnose โ ls -la ~/.ssh and ssh -vvv host.
Fix โ
chmod 700 ~/.ssh && chmod 600 ~/.ssh/config ~/.ssh/id_*
chown -R "$USER": ~/.sshPrevent โ Do not mount .ssh from shared volumes with loose permissions into containers.
Q17 kex_exchange_identification: read: Connection reset by peer during large runs
Advanced
kex_exchange_identification: read: Connection reset by peer during large runsLikely causes โ Too many parallel handshakes exceeding sshd MaxStartups, fail2ban banning the controller, or a bastion with connection limits.
Diagnose โ On the target: journalctl -u sshd | grep -i 'drop\|exceeded' and fail2ban-client status sshd.
Fix โ Lower forks, enable ControlPersist so handshakes are reused, whitelist the controller in fail2ban, raise MaxStartups 100:30:200.
Prevent โ Size forks to the weakest hop in the path.
Q18 UNREACHABLE! => {"msg": "Failed to connect ... Connection closed by 10.0.1.15 port 22"}
Intermediate
UNREACHABLE! => {"msg": "Failed to connect ... Connection closed by 10.0.1.15 port 22"}Likely causes โ AllowUsers or AllowGroups excludes the user, TCP wrappers, fail2ban, or unsupported key algorithm (for example ssh-rsa disabled on newer OpenSSH).
Diagnose โ
ssh -vvv [email protected]
# server side
journalctl -u sshd -n 50Fix โ Add the user to AllowUsers, or use an Ed25519 key. For old targets only, -o PubkeyAcceptedAlgorithms=+ssh-rsa as a stopgap.
Prevent โ Keep sshd hardening in a role that always includes the automation user.
Q19 ssh: connect to host ... port 22: Network is unreachable from inside a container controller
Intermediate
ssh: connect to host ... port 22: Network is unreachable from inside a container controllerLikely causes โ Container network has no route to the target subnet, VPN not available in the container, or IPv6/IPv4 mismatch.
Diagnose โ docker exec ctl ip route, ping/nc from inside the container.
Fix โ Run with --network host or attach to the right network, mount VPN config, or use a bastion in the inventory.
Prevent โ Document the network model for the execution environment.
Q20 Playbook works on the first run, later runs fail with Connection reset by peer right after a handler restarts sshd
Intermediate
Connection reset by peer right after a handler restarts sshdLikely causes โ restarted kills the connection Ansible is using; or a config error prevents sshd from coming back.
Diagnose โ Check systemctl status sshd from the console; verify with sshd -t.
Fix โ Use state: reloaded, validate before installing the config, and add meta: reset_connection after the change.
- ansible.builtin.meta: reset_connectionPrevent โ validate: sshd -t -f %s on every sshd config task.
Q21 fatal: [web01]: FAILED! => {"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"}
Beginner
fatal: [web01]: FAILED! => {"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"}Likely causes โ Password SSH is requested (ansible_password or -k) but sshpass is missing on the controller.
Diagnose โ which sshpass.
Fix โ apt install sshpass or dnf install sshpass, or switch to key auth, which is preferred.
Prevent โ Use keys; reserve passwords for first-time bootstrapping.
Q22 After a reboot task: fatal: [web01]: FAILED! => {"msg": "Timed out waiting for last boot time check (timeout=600)"}
Intermediate
fatal: [web01]: FAILED! => {"msg": "Timed out waiting for last boot time check (timeout=600)"}Likely causes โ The host takes longer than the timeout to boot, networking or SSH does not come up, or boot_time_command fails.
Diagnose โ Console log, ansible web01 -m ping repeatedly, check cloud-init and fsck delays.
Fix โ
- ansible.builtin.reboot:
reboot_timeout: 1800
connect_timeout: 10
post_reboot_delay: 30Fix the slow-boot cause (large fsck, network wait).
Prevent โ Test reboots in staging and set realistic timeouts.
Q23 fatal: [localhost]: UNREACHABLE! Failed to connect to the host via ssh: Permission denied when targeting localhost
Beginner
fatal: [localhost]: UNREACHABLE! Failed to connect to the host via ssh: Permission denied when targeting localhostLikely causes โ A host named localhost in your own inventory overrides the implicit local connection and Ansible tries SSH.
Diagnose โ ansible-inventory --host localhost and look for ansible_connection.
Fix โ
localhost ansible_connection=localor use connection: local in the play.
Prevent โ Always set connection: local for control-node plays.
Q24 Failed to connect to the host via ssh: channel 0: open failed: administratively prohibited when using a bastion
Advanced
Failed to connect to the host via ssh: channel 0: open failed: administratively prohibited when using a bastionLikely causes โ The bastion's sshd has AllowTcpForwarding no or PermitOpen restrictions, which block ProxyJump or ProxyCommand with -W.
Diagnose โ ssh -vvv -J bastion target and inspect the bastion's sshd_config.
Fix โ Allow TCP forwarding for the automation user on the bastion (AllowTcpForwarding yes or a Match User block), or use SSM Session Manager.
Prevent โ Include the jump requirements in the bastion build.
Q25 ansible-playbook prints [WARNING]: Platform linux on host web01 is using the discovered Python interpreter ... but future installation of another Python interpreter could change the meaning
Beginner
ansible-playbook prints [WARNING]: Platform linux on host web01 is using the discovered Python interpreter ... but future installation of another Python interpreter could change the meaningLikely causes โ Interpreter auto-discovery is working but warns it may change.
Diagnose โ ansible web01 -m setup -a 'filter=ansible_python*'.
Fix โ Pin it per host/group (ansible_python_interpreter=/usr/bin/python3), or set interpreter_python = auto_silent in ansible.cfg.
Prevent โ Set the interpreter in group_vars/all.yml.
Privilege Escalation and Python Interpreter Issues
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q26 fatal: [web01]: FAILED! => {"msg": "Missing sudo password"}
Beginner
fatal: [web01]: FAILED! => {"msg": "Missing sudo password"}Likely causes โ become: true is set but the user needs a password and none was supplied.
Diagnose โ ssh host 'sudo -n true' returns "a password is required".
Fix โ Run with -K, set ansible_become_password from Vault, or configure NOPASSWD for the automation user.
Prevent โ Provision a sudoers drop-in at bootstrap: ansible ALL=(ALL) NOPASSWD: ALL (or a restricted command list).
Q27 sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
Intermediate
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helperLikely causes โ No password supplied and sudo wants a TTY; sometimes requiretty in sudoers.
Diagnose โ sudo -l -U ansible and check for Defaults requiretty.
Fix โ Provide the password, or give NOPASSWD. Remove requiretty (Defaults:ansible !requiretty), especially with pipelining.
Prevent โ Bake the sudoers entry into your base image.
Q28 sudo: sorry, you must have a tty to run sudo
Intermediate
sudo: sorry, you must have a tty to run sudoLikely causes โ Defaults requiretty in /etc/sudoers (older RHEL/CentOS) and pipelining enabled.
Diagnose โ grep requiretty /etc/sudoers /etc/sudoers.d/*.
Fix โ
Defaults:ansible !requirettyor disable pipelining.
Prevent โ Use visudo -cf validation when deploying sudoers files.
Q29 FAILED! => {"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chmod: invalid mode: 'A+user:app:rx:allow')"}
Advanced
FAILED! => {"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chmod: invalid mode: 'A+user:app:rx:allow')"}Likely causes โ Both the login user and become_user are unprivileged and the system can't use ACLs (setfacl missing or no ACL support on the filesystem).
Diagnose โ which setfacl, mount | grep acl.
Fix โ Install acl, enable pipelining (pipelining = True), or as a last resort allow_world_readable_tmpfiles = True.
Prevent โ Include acl in the base image and enable pipelining.
Q30 "msg": "/bin/sh: 1: /usr/bin/python: not found" or "The module failed to execute correctly, you probably need to set the interpreter."
Beginner
"msg": "/bin/sh: 1: /usr/bin/python: not found" or "The module failed to execute correctly, you probably need to set the interpreter."Likely causes โ Target has no Python, or only python3 at a different path.
Diagnose โ ansible web01 -m raw -a 'which python3 python'.
Fix โ Bootstrap Python with raw, or set ansible_python_interpreter=/usr/bin/python3.
- ansible.builtin.raw: test -e /usr/bin/python3 || (apt-get update && apt-get install -y python3)
changed_when: falsePrevent โ Bake Python in the image, or cloud-init it.
Q31 ModuleNotFoundError: No module named 'apt' / Could not import python modules: apt, apt_pkg. Please install python3-apt package.
Intermediate
ModuleNotFoundError: No module named 'apt' / Could not import python modules: apt, apt_pkg. Please install python3-apt package.Likely causes โ Ansible is using a Python interpreter (often a virtualenv or a custom /usr/local/bin/python3) that lacks the system python3-apt.
Diagnose โ
ansible web01 -m setup -a 'filter=ansible_python_interpreter'
ansible web01 -m raw -a '/usr/bin/python3 -c "import apt"'Fix โ Point to /usr/bin/python3, or install python3-apt for that interpreter.
Prevent โ Do not override the interpreter with a venv for system-package tasks.
Q32 FAILED! => {"msg": "The Python 2 yum module is needed for this module"}
Intermediate
FAILED! => {"msg": "The Python 2 yum module is needed for this module"}Likely causes โ Using the yum module on a host whose default Python is 3 but python3-dnf/yum bindings are missing, or on a modern host where dnf should be used.
Diagnose โ rpm -q python3-dnf.
Fix โ Use ansible.builtin.dnf (or package), and install python3-dnf.
Prevent โ Use ansible.builtin.package for portability.
Q33 Unable to encode the result: "AnsiballZ" ... SyntaxError: invalid syntax when targeting an old CentOS 6 host
Advanced
Unable to encode the result: "AnsiballZ" ... SyntaxError: invalid syntax when targeting an old CentOS 6 hostLikely causes โ Python on the target is too old for the Ansible version's modules (current ansible-core needs Python 3.8+ on targets; Python 2.7 support is gone).
Diagnose โ ansible web01 -m raw -a 'python --version' and ansible --version.
Fix โ Install a newer Python on the host, or use an older ansible-core supported for that target, or upgrade the OS.
Prevent โ Track the target Python support matrix on every Ansible upgrade.
Q34 fatal: [web01]: FAILED! => {"msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}
Intermediate
fatal: [web01]: FAILED! => {"msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}Likely causes โ SELinux is enabled and the Python SELinux bindings are not available to the interpreter in use.
Diagnose โ getenforce, rpm -q python3-libselinux.
Fix โ
ansible web01 -b -m ansible.builtin.dnf -a "name=python3-libselinux state=present"Use the system interpreter (not a venv).
Prevent โ Include python3-libselinux in the base image.
Q35 become_method su fails: Timeout (12s) waiting for privilege escalation prompt
Intermediate
become_method su fails: Timeout (12s) waiting for privilege escalation promptLikely causes โ su prompt localised or different, wrong root password, or PAM restrictions.
Diagnose โ ansible web01 -b --become-method su -K -m ping -vvv.
Fix โ Provide the correct ansible_become_password, set LANG=C through ansible_shell_executable/environment, or switch to sudo.
Prevent โ Standardise on sudo.
Q36 FAILED! => {"msg": "Incorrect sudo password"} for one host only
Beginner
FAILED! => {"msg": "Incorrect sudo password"} for one host onlyLikely causes โ Host-specific password differs from the rest or account locked after bad attempts.
Diagnose โ ssh -t host sudo -v; check faillock or pam_tally2.
Fix โ Set the host's own ansible_become_password in host_vars, reset the faillock: faillock --user ansible --reset.
Prevent โ Use passwordless sudo and consistent accounts.
Q37 chown: invalid user: 'appuser' when running the file or copy module
Beginner
chown: invalid user: 'appuser' when running the file or copy moduleLikely causes โ The user does not exist yet; ordering issue.
Diagnose โ getent passwd appuser.
Fix โ Create the user earlier in the play (the user module before copy).
Prevent โ Put identities first in role task order.
Q38 failed to resolve remote temporary directory from ansible-tmp-...: 'mkdir -p ... ' failed: Permission denied
Intermediate
failed to resolve remote temporary directory from ansible-tmp-...: 'mkdir -p ... ' failed: Permission deniedLikely causes โ Home directory not writable or full disk, read-only filesystem, or remote_tmp points to an unwritable location.
Diagnose โ df -h ~ /tmp, touch ~/.ansible/tmp/x, check mount flags.
Fix โ Fix permissions or free disk. Set remote_tmp = /tmp/.ansible-${USER}/tmp in ansible.cfg when homes are read-only.
Prevent โ Alert on disk usage and use remote_tmp for locked-down hosts.
Q39 Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory.
Intermediate
Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory.Likely causes โ Same family as Q38: the remote user cannot create ~/.ansible/tmp; or SSH auth truly failed.
Diagnose โ Run with -vvv; check the full "mkdir" command and its stderr; ls -ld ~ ~/.ansible.
Fix โ Correct home directory ownership (chown -R user: ~), or set remote_tmp.
Prevent โ Do not run Ansible as a user whose home is root-owned.
Q40 The conditional check 'ansible_distribution == "Ubuntu"' failed. The error was: error while evaluating conditional: 'ansible_distribution' is undefined
Intermediate
The conditional check 'ansible_distribution == "Ubuntu"' failed. The error was: error while evaluating conditional: 'ansible_distribution' is undefinedLikely causes โ gather_facts: false, facts failed to gather, or injected facts disabled (inject_facts_as_vars = False).
Diagnose โ ansible web01 -m setup -a 'filter=ansible_distribution'.
Fix โ Enable fact gathering or run setup; use ansible_facts['distribution'].
Prevent โ Always use the ansible_facts[...] form.
Q41 Shared connection to web01 closed. and the command output is truncated or garbled after become
Intermediate
Shared connection to web01 closed. and the command output is truncated or garbled after becomeLikely causes โ Interactive shell startup scripts, banners, or MOTD printing on non-interactive logins, or a custom login shell.
Diagnose โ ssh web01 true | xxd | head to look for extra output; check /etc/profile.d, .bashrc, .bash_profile.
Fix โ Remove output from shell profiles for the automation user (guard with an interactive check) and disable banners. Keep the user's shell as /bin/bash.
Prevent โ Lint the base image for profile noise.
Q42 The module failed to execute correctly, you probably need to set the interpreter. with /usr/bin/env: 'python': No such file or directory
Beginner
The module failed to execute correctly, you probably need to set the interpreter. with /usr/bin/env: 'python': No such file or directoryLikely causes โ Only python3 exists; module shebang or discovery found no python.
Diagnose โ ansible web01 -m raw -a 'command -v python python3'.
Fix โ -e ansible_python_interpreter=/usr/bin/python3, or install Python.
Prevent โ Use interpreter_python = auto and Python 3 images.
Q43 sudo: /etc/sudoers.d/ansible: syntax error near line 1 and now nobody can sudo
Advanced
sudo: /etc/sudoers.d/ansible: syntax error near line 1 and now nobody can sudoLikely causes โ A broken sudoers file deployed without validation.
Diagnose โ From a root console: visudo -c.
Fix โ Remove or fix the broken file as root (cloud console or rescue mode). Then:
- ansible.builtin.copy:
dest: /etc/sudoers.d/ansible
content: "ansible ALL=(ALL) NOPASSWD: ALL\n"
mode: "0440"
validate: /usr/sbin/visudo -cf %sPrevent โ Always use validate for sudoers and sshd files.
Q44 FAILED! => {"msg": "Failed to get information on remote file (/path): MODULE FAILURE ... Permission denied"}
Beginner
FAILED! => {"msg": "Failed to get information on remote file (/path): MODULE FAILURE ... Permission denied"}Likely causes โ The task runs as an unprivileged user and cannot read the path.
Diagnose โ ansible web01 -m stat -a path=/path -b vs. without -b.
Fix โ Add become: true to the task (or the required group access).
Prevent โ Set become at the play level when most tasks need root.
Q45 unable to resolve ... ansible_python_interpreter after switching from Python 2 to 3 on Ubuntu 20.04 hosts: /usr/bin/python: No such file or directory
Beginner
unable to resolve ... ansible_python_interpreter after switching from Python 2 to 3 on Ubuntu 20.04 hosts: /usr/bin/python: No such file or directoryLikely causes โ An old inventory still pins ansible_python_interpreter=/usr/bin/python.
Diagnose โ grep -rn ansible_python_interpreter inventories group_vars host_vars.
Fix โ Remove the pin or change it to /usr/bin/python3.
Prevent โ Prefer auto discovery.
Q46 Ansible runs, but become_user: postgres tasks fail with could not change directory to "/root": Permission denied
Intermediate
become_user: postgres tasks fail with could not change directory to "/root": Permission deniedLikely causes โ psql runs from the login user's working directory, which the target user cannot access.
Diagnose โ Run sudo -u postgres psql -c 'select 1' from /root.
Fix โ
- community.postgresql.postgresql_db: { name: app }
become: true
become_user: postgres
vars:
ansible_remote_tmp: /tmp/.ansible-postgresor use chdir: /tmp on command tasks.
Prevent โ Use chdir for commands and community modules for DB work.
Q47 Failed to lock apt for exclusive operation or Could not get lock /var/lib/dpkg/lock-frontend
Intermediate
Failed to lock apt for exclusive operation or Could not get lock /var/lib/dpkg/lock-frontendLikely causes โ unattended-upgrades, cloud-init or another apt process holds the lock, often right after boot.
Diagnose โ fuser -v /var/lib/dpkg/lock-frontend, ps aux | grep -E 'apt|dpkg'.
Fix โ
- ansible.builtin.apt:
name: nginx
lock_timeout: 300Or wait for cloud-init: cloud-init status --wait.
Prevent โ Use lock_timeout and disable unattended upgrades on build/bootstrap windows.
Q48 E: Unable to locate package nginx on a fresh Ubuntu host
Beginner
E: Unable to locate package nginx on a fresh Ubuntu hostLikely causes โ The apt cache has never been updated.
Diagnose โ apt-cache policy nginx.
Fix โ
- ansible.builtin.apt:
name: nginx
update_cache: true
cache_valid_time: 3600Prevent โ Always use update_cache with cache_valid_time in bootstrap roles.
Q49 No package matching 'httpd' is available on Ubuntu
Beginner
No package matching 'httpd' is available on UbuntuLikely causes โ Package name differs by distro (apache2 on Debian family).
Diagnose โ ansible web01 -m setup -a 'filter=ansible_os_family'.
Fix โ Use a vars map per OS family and the package module.
Prevent โ Define distro-specific names in vars/<os_family>.yml.
Q50 fatal: [web01]: FAILED! => {"msg": "Could not find the requested service nginx: host"}
Beginner
fatal: [web01]: FAILED! => {"msg": "Could not find the requested service nginx: host"}Likely causes โ The service/unit does not exist (package not installed, or typo) or the init system is not detected (container without systemd).
Diagnose โ systemctl list-unit-files | grep nginx; inside a container check PID 1.
Fix โ Install the package first; use ansible.builtin.systemd explicitly. In containers use a systemd-enabled image or skip service tasks.
Prevent โ Order tasks install โ configure โ service; test with Molecule on systemd images.
YAML, Syntax and Jinja2 Errors
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q51 Syntax Error while loading YAML. mapping values are not allowed in this context
Beginner
Syntax Error while loading YAML. mapping values are not allowed in this contextLikely causes โ A colon followed by a space inside an unquoted value (msg: Status: OK), or a key indented under a scalar instead of a mapping.
Diagnose โ
ansible-playbook site.yml --syntax-check
yamllint site.ymlThe error prints the file, line and column with a caret under the offending character. The real mistake is often on the line above.
Fix โ Quote the value: msg: "Status: OK", or fix the indentation so the key belongs to a mapping.
Prevent โ Run yamllint and ansible-lint as a pre-commit hook. Quote any string that contains : , #, { or starts with *, &, @.
Q52 found character '\t' that cannot start any token
Beginner
found character '\t' that cannot start any tokenLikely causes โ A tab character. YAML only allows spaces for indentation. This usually comes from an editor that inserts tabs, or from copy-pasting out of a terminal or a wiki.
Diagnose โ
grep -nP '\t' roles/web/tasks/main.yml
cat -A roles/web/tasks/main.yml | grep '\^I'Fix โ Replace the tabs with spaces: sed -i 's/\t/ /g' file.yml, then re-check the indentation.
Prevent โ Add an .editorconfig with indent_style = space for *.yml, and run yamllint in CI.
Q53 ERROR! conflicting action statements: ansible.builtin.copy, dest
Intermediate
ERROR! conflicting action statements: ansible.builtin.copy, destLikely causes โ The module arguments are dedented to the task level, so Ansible sees copy and dest as two separate keys and tries to treat both as modules. A misspelled task keyword (notifiy:, whn:) gives the same error, because Ansible treats unknown keys as possible actions.
Diagnose โ Look at the task the error points to:
- name: Copy config
ansible.builtin.copy:
src: app.conf # wrong: same level as the module
dest: /etc/app.confFix โ Indent the arguments under the module, and fix any misspelled keywords.
Prevent โ ansible-lint catches both problems. Editor YAML schemas (the Red Hat Ansible VS Code extension) flag them as you type.
Q54 Ansible says This one looks easy to fix. It seems that there is a value started with a quote, and the YAML parser is expecting to see the line ended with the same kind of quote.
Beginner
This one looks easy to fix. It seems that there is a value started with a quote, and the YAML parser is expecting to see the line ended with the same kind of quote.Likely causes โ A value starts with a quote but has text after the closing quote:
cmd: "/opt/app/bin/start" --port 8080Diagnose โ --syntax-check shows the line. Look for a quote that closes partway through the value.
Fix โ Quote the whole value: cmd: "/opt/app/bin/start --port 8080", or use single quotes on the outside when the value contains double quotes.
Prevent โ For long commands, use the YAML folded style (>-) or the argv: list form of command, which avoids quoting completely.
Q55 We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value.
Beginner
We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value.Likely causes โ A value starts with {{. YAML reads { as the start of an inline dictionary.
dest: {{ app_dir }}/config.yml # brokenFix โ
dest: "{{ app_dir }}/config.yml"Prevent โ The rule is simple: if a value starts with {{, wrap the whole value in quotes. ansible-lint and yamllint both catch this.
Q56 ERROR! A malformed block was encountered while loading tasks: {...} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>
Intermediate
ERROR! A malformed block was encountered while loading tasks: {...} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>Likely causes โ A tasks file (tasks/main.yml, or a file loaded with include_tasks/import_tasks) holds a mapping at the top level instead of a list. This usually means the leading - on the first task is missing. A related mistake is putting a whole play (hosts:, tasks:) into a file that is included as tasks.
Diagnose โ Open the file the error names. Its first line must be - name: ..., not name: ....
Fix โ Turn the content into a list of tasks. If the file is really a play, load it with import_playbook at the playbook level instead of import_tasks.
Prevent โ Keep a clear split: playbooks/*.yml hold plays, and tasks/*.yml hold task lists only.
Q57 ERROR! 'tsks' is not a valid attribute for a Play
Beginner
ERROR! 'tsks' is not a valid attribute for a PlayLikely causes โ A typo in a play-level keyword (tsks, handler, var, gather_fact), or a task keyword such as become_pass used at play level.
Diagnose โ The error names the bad key. Compare it with the valid play keywords: ansible-doc -t keyword -l.
Fix โ Correct the spelling. For example, use tasks, handlers, vars and gather_facts.
Prevent โ ansible-lint with schema validation catches these before they reach a run.
Q58 template error while templating string: expected token 'end of print statement', got 'name'
Intermediate
template error while templating string: expected token 'end of print statement', got 'name'Likely causes โ Invalid Jinja inside {{ }}. Common causes are a space in a variable name ({{ user name }}), a hyphen ({{ app-port }} is read as subtraction), or two expressions with no operator between them.
Diagnose โ Test the expression on its own:
ansible localhost -m debug -a 'msg={{ user_name | upper }}' -e user_name=bobFix โ Use valid identifiers (user_name), use bracket notation for keys with special characters ({{ item['app-port'] }}), and join strings with ~.
Prevent โ Name variables in snake_case. ansible-lint rule var-naming enforces this.
Q59 The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout' after a looped register
Intermediate
The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout' after a looped registerLikely causes โ When a task runs with loop, the registered variable does not have stdout. It has a results list with one entry per item.
Diagnose โ
- ansible.builtin.debug:
var: check_outYou will see results: [ {item: ..., stdout: ...}, ... ].
Fix โ
- ansible.builtin.debug:
msg: "{{ check_out.results | map(attribute='stdout') | list }}"Prevent โ Always debug a registered variable once while you develop. Name looped registers in the plural (checks) so readers expect a list.
Q60 'item' is undefined even though the task has a loop
Beginner
'item' is undefined even though the task has a loopLikely causes โ loop: is indented under the module arguments instead of at task level. Ansible renders the module arguments first, so {{ item }} is undefined. If that did not fail, you would see Unsupported parameters for (ansible.builtin.apt) module: loop.
Diagnose โ
- ansible.builtin.apt:
name: "{{ item }}"
loop: [git, curl] # wrong levelFix โ Dedent loop: so it lines up with ansible.builtin.apt:. Better still, pass the list directly with name: [git, curl], which is faster too.
Prevent โ loop, when, register, notify and become are task keywords. They always sit at the same indentation as the module name.
Q61 [WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ env }} == 'prod'
Beginner
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ env }} == 'prod'Likely causes โ when:, failed_when:, changed_when: and until: are already Jinja expressions. Wrapping them in {{ }} templates the expression twice. Newer ansible-core releases are stricter, so this is a time bomb.
Fix โ
when: env == 'prod'To build a variable name dynamically, use lookup('vars', 'port_' ~ env) or hostvars[inventory_hostname]['port_' ~ env], not nested braces.
Prevent โ ansible-lint rule no-jinja-when flags this.
Q62 The conditional check 'result.rc == 0' failed. The error was: error while evaluating conditional (result.rc == 0): 'dict object' has no attribute 'rc'
Intermediate
The conditional check 'result.rc == 0' failed. The error was: error while evaluating conditional (result.rc == 0): 'dict object' has no attribute 'rc'Likely causes โ The task that registered result was skipped (its when was false, or it was a command running in --check mode). A skipped result has skipped: true and no rc.
Diagnose โ debug: var=result and look for "skipped": true or "msg": "Command would have run if not in check mode".
Fix โ
when: result is not skipped and result.rc == 0
# or
when: (result.rc | default(1)) == 0For read-only commands that must run in check mode, add check_mode: false.
Prevent โ Use the test plugins is succeeded, is failed, is skipped and is changed instead of raw attributes.
Q63 template error while templating string: No filter named 'json_query'
Intermediate
template error while templating string: No filter named 'json_query'Likely causes โ json_query is part of community.general, not ansible-core. With a minimal ansible-core install, that collection is not present. When the collection is present but the Python library is missing, you get You need to install "jmespath" prior to running json_query filter instead.
Diagnose โ
ansible-galaxy collection list community.general
python3 -c 'import jmespath' # on the controllerFix โ Install community.general and pip install jmespath into the controller's Python, and call the filter by its FQCN, community.general.json_query. Often the cleaner fix is to drop JMESPath and use core filters: selectattr, map(attribute=...) and items2dict.
Prevent โ Pin collections in collections/requirements.yml and Python dependencies in requirements.txt, and build both into your execution environment.
Q64 A when: enable_tls task runs even though the job was started with -e enable_tls=false
Advanced
when: enable_tls task runs even though the job was started with -e enable_tls=falseLikely causes โ -e key=value always passes a string. The string "false" is not empty, so Jinja treats it as truthy. On ansible-core 2.19+ this is an error instead: Conditionals must have a boolean result.
Diagnose โ
- ansible.builtin.debug:
msg: "{{ enable_tls | type_debug }}" # prints AnsibleUnicode / strFix โ
ansible-playbook site.yml -e '{"enable_tls": false}' # JSON keeps the typeor in the play: when: enable_tls | bool.
Prevent โ Use | bool on every flag that can come from -e, a survey or an environment variable, and declare flag types in meta/argument_specs.yml so bad input fails early.
Q65 recursive loop detected in template string: {{ app_port | default(8080) }}
Advanced
recursive loop detected in template string: {{ app_port | default(8080) }}Likely causes โ A variable is defined in terms of itself, for example app_port: "{{ app_port | default(8080) }}" in vars: or group_vars. Ansible evaluates variables lazily, so the reference never resolves.
Diagnose โ Search for the self-reference: grep -rn 'app_port:.*app_port' .
Fix โ Use two names, so that the defaults layer supplies the base value:
# roles/app/defaults/main.yml
app_port: 8080
# a computed value gets its own name
app_listen: "0.0.0.0:{{ app_port }}"If you must "add to" a list or dict, build a new variable from the old one (app_pkgs_final: "{{ app_pkgs + extra_pkgs }}").
Prevent โ Treat variables as immutable bindings, not assignments. Defaults belong in defaults/main.yml, not in self-referencing expressions.
Q66 template error while templating string: unexpected char '$' at 18 when deploying Prometheus alert rules
Intermediate
template error while templating string: unexpected char '$' at 18 when deploying Prometheus alert rulesLikely causes โ The file contains its own {{ }} syntax (Prometheus {{ $labels.instance }}, Go templates, Helm charts, GitHub Actions ${{ }}), and Ansible tries to render it as Jinja.
Fix โ Choose one of these:
{% raw %}summary: "{{ $labels.instance }} is down"{% endraw %}- Use
copyinstead oftemplateif the file has no Ansible variables at all. - Change the delimiters for this one file by putting a header on the first line:
#jinja2: variable_start_string:'[[', variable_end_string:']]'. - Mark a variable value as
!unsafeso it is never templated.
Prevent โ Keep third-party template files under files/, not templates/.
Q67 Unexpected end of template. Jinja was looking for the following tags: 'endif' or 'else' or 'elif'. The innermost block that needs to be closed is 'if'.
Beginner
Unexpected end of template. Jinja was looking for the following tags: 'endif' or 'else' or 'elif'. The innermost block that needs to be closed is 'if'.Likely causes โ A missing {% endif %} or {% endfor %} in a .j2 file, or an {% if %} hidden inside a comment line of the target format.
Diagnose โ The error names the template. Count the blocks quickly:
grep -cE '\{%-? *if ' templates/nginx.conf.j2
grep -cE '\{%-? *endif' templates/nginx.conf.j2Fix โ Close every block. Indent nested blocks inside the template so they are easy to see.
Prevent โ Render templates in CI with a test playbook (template with delegate_to: localhost into a temporary directory), or with ansible-playbook --check --diff in Molecule.
Q68 The rendered Nginx config has random blank lines and broken indentation
Beginner
Likely causes โ Jinja keeps the newline after each {% %} tag and the spaces in front of it. With the template module's defaults (trim_blocks: true, lstrip_blocks: false), indented block tags still leave stray whitespace behind.
Fix โ
- ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
lstrip_blocks: trueOr use whitespace control in the template: {%- for s in servers %} / {% endfor -%}.
Prevent โ Add #jinja2: lstrip_blocks: True as the first line of complex templates, and review the --diff output in pull requests.
Q69 File permissions come out as --w----r-T after setting mode: 644
Intermediate
--w----r-T after setting mode: 644Likely causes โ An unquoted 644 is the decimal integer 644, which is octal 1204: sticky bit, owner write, other read. An unquoted 0644 happens to work because YAML 1.1 reads it as octal, but that is fragile.
Diagnose โ stat -c '%a %A' /etc/app.conf prints 1204 --w----r-T.
Fix โ
mode: "0644" # or the symbolic form: "u=rw,g=r,o=r"Prevent โ Always quote modes. ansible-lint rules risky-octal and risky-file-permissions catch this.
Q70 A package pinned as version: 1.10 installs 1.1
Intermediate
version: 1.10 installs 1.1Likely causes โ YAML parses 1.10 as the float 1.1. Similar traps: NO (country code Norway) becomes false, on/yes become true, and 012 becomes octal 10.
Diagnose โ debug: msg="{{ app_version }} {{ app_version | type_debug }}" prints 1.1 float.
Fix โ Quote it: app_version: "1.10". Do the same for version numbers, ZIP codes, phone numbers and any string made of digits.
Prevent โ Enable yamllint rule truthy with allowed-values: ['true', 'false'], and quote every value that is not meant to be a number.
Q71 did not find expected '-' indicator while parsing a block collection
Beginner
did not find expected '-' indicator while parsing a block collectionLikely causes โ Items in a list have mixed indentation, or a key line was inserted between list items at the wrong level:
tasks:
- name: one
ansible.builtin.ping:
- name: two # one space offDiagnose โ The error points to the line where the parser expected a -. Compare the column of every - in that list.
Fix โ Line up all list items at the same column.
Prevent โ Use 2-space indentation consistently, and run yamllint -d '{rules: {indentation: {spaces: 2}}}'.
Q72 ERROR! no module/action detected in task.
Beginner
ERROR! no module/action detected in task.Likely causes โ The task has a name, when or tags but no module, usually because the module line was deleted or commented out. Older versions said no action detected in task. This often indicates a misspelled module name, or incorrect module path.
Diagnose โ Open the task that the error points to and check it has exactly one module key.
Fix โ Add the module back, or delete the leftover task. For a no-op placeholder, use ansible.builtin.meta: noop.
Prevent โ Do not leave half-commented tasks in the main branch. Review diffs of task files carefully.
Q73 CI fails on ansible-lint with yaml[truthy], fqcn[action-core], name[missing] and no-changed-when
Intermediate
yaml[truthy], fqcn[action-core], name[missing] and no-changed-whenLikely causes โ The lint profile was raised (for example to production), or ansible-lint was upgraded and added rules.
Diagnose โ
ansible-lint --version
ansible-lint -p # parseable output, one violation per lineFix โ
yaml[truthy]: usetrue/falseinstead ofyes/no.fqcn[action-core]: writeansible.builtin.copyinstead ofcopy.name[missing]: give every task a name.no-changed-when: addchanged_whentocommandandshelltasks.
For a large legacy codebase, run ansible-lint --fix first, then review the diff.
Prevent โ Pin the ansible-lint version in requirements-dev.txt, and set the profile in .ansible-lint. Use --generate-ignore to accept the existing violations and stop new ones.
Q74 Unexpected templating type error occurred on ({{ base_port + port_offset }}): unsupported operand type(s) for +: 'int' and 'str'
Intermediate
Unexpected templating type error occurred on ({{ base_port + port_offset }}): unsupported operand type(s) for +: 'int' and 'str'Likely causes โ One of the operands is a string. It came from -e port_offset=10, an AWX survey text field, a lookup('env', ...) or stdout.
Fix โ
listen_port: "{{ base_port | int + port_offset | int }}"For lists, + needs a list on both sides: "{{ list_a + [single_item] }}".
Prevent โ Cast at the boundary where data enters the playbook (| int, | bool, | from_json), and declare type: int in meta/argument_specs.yml.
Q75 ansible-playbook --syntax-check passes, but the run fails immediately on an undefined variable
Beginner
ansible-playbook --syntax-check passes, but the run fails immediately on an undefined variableLikely causes โ --syntax-check only parses YAML and play structure. It does not render templates, resolve variables, run dynamic includes or check that modules exist.
Diagnose โ
ansible-playbook site.yml --check --diff -l staging-web01
ansible-inventory -i inventories/prod --host web01 --varsFix โ Define the variable where it belongs: role defaults/ for sensible defaults, or group_vars for environment values. Fail early with an assert:
- ansible.builtin.assert:
that: [db_host is defined, db_host | length > 0]
fail_msg: "db_host must be set in group_vars"Prevent โ Use a layered CI: yamllint โ ansible-lint โ --syntax-check โ Molecule converge. Add meta/argument_specs.yml for required role inputs.
Variables, Facts and Precedence Problems
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q76 Variables in group_vars/webservers.yml are silently ignored
Beginner
group_vars/webservers.yml are silently ignoredLikely causes โ Ansible only loads group_vars/ and host_vars/ from two places: next to the inventory source and next to the playbook. A group_vars/ folder anywhere else (repo root, roles/) is not read. A filename that does not match the group name exactly (webserver.yml against group webservers) is also skipped.
Diagnose โ
ansible-inventory -i inventories/prod/hosts.yml --host web01 --vars
ansible-inventory -i inventories/prod/hosts.yml --graphIf the variable is not shown, Ansible never loaded it.
Fix โ Move the folder to inventories/prod/group_vars/webservers.yml, or next to the playbook. Make the filename match the group name.
Prevent โ Use the standard layout of one inventory directory per environment, each with its own group_vars/ and host_vars/.
Q77 You set nginx_port: 8443 in inventory group_vars, but the role still uses 80
Intermediate
nginx_port: 8443 in inventory group_vars, but the role still uses 80Likely causes โ The role defines nginx_port in roles/nginx/vars/main.yml. Role vars/ are higher in precedence than inventory group_vars and host_vars. Only defaults/main.yml is lower.
Diagnose โ
grep -rn 'nginx_port' roles/nginx/Fix โ Move tunable values to roles/nginx/defaults/main.yml. Keep vars/main.yml for internal constants that callers must never change, such as package names per OS.
Prevent โ Use this convention in code review: anything a user may override goes in defaults/, prefixed with the role name.
Q78 set_fact: release_tag=v2 runs, but later tasks still see v1
Intermediate
set_fact: release_tag=v2 runs, but later tasks still see v1Likely causes โ release_tag was also passed with -e (or comes from an AWX survey or extra vars). Extra vars have the highest precedence and override set_fact, register and everything else.
Diagnose โ Check the job command line and the AWX extra vars or survey. debug: var=release_tag straight after the set_fact still shows v1.
Fix โ Use a different name for the computed value (release_tag_effective), or stop passing the key as an extra var.
Prevent โ Reserve extra vars for true run-time inputs, and never reuse those names for internal facts.
Q79 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4' when templating hostvars['db01']
Intermediate
'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4' when templating hostvars['db01']Likely causes โ Facts for db01 were never gathered in this run. Either db01 is not in the current play, or --limit web* excluded it, so only inventory variables exist for it.
Diagnose โ
- ansible.builtin.debug:
msg: "{{ hostvars['db01'].keys() | list }}"Fix โ Gather facts for the database hosts first:
- hosts: dbservers
gather_facts: true
tasks: []
- hosts: webservers
tasks: ...Alternatively, use ansible.builtin.setup with delegate_to: "{{ item }}" and delegate_facts: true over groups['dbservers'], or turn on a fact cache.
Prevent โ Put stable addresses in inventory variables (db_private_ip) instead of relying on another host's facts.
Q80 'ansible_eth0' is undefined on new cloud instances
Beginner
'ansible_eth0' is undefined on new cloud instancesLikely causes โ Interface names depend on the hardware and OS: ens5 on Nitro EC2, enp0s3 on VirtualBox, eth0 on older images. Hard-coding eth0 breaks when the instance type changes.
Diagnose โ ansible web01 -m setup -a 'filter=ansible_interfaces'
Fix โ Use the interface-independent facts:
bind_ip: "{{ ansible_facts['default_ipv4']['address'] }}"Prevent โ Never reference a fact named after an interface in a role. Use default_ipv4, all_ipv4_addresses, or inventory variables.
Q81 Facts like ansible_hostname became undefined after someone changed ansible.cfg
Intermediate
ansible_hostname became undefined after someone changed ansible.cfgLikely causes โ inject_facts_as_vars = False was set. Facts are then only available under ansible_facts, not as top-level ansible_* variables. Recent ansible-core releases also warn about relying on the injected names.
Diagnose โ ansible-config dump --only-changed | grep -i inject
Fix โ Update the code to the namespaced form:
"{{ ansible_facts['hostname'] }}" # not ansible_hostname
"{{ ansible_facts['os_family'] }}" # not ansible_os_familyPrevent โ Write all new roles with ansible_facts[...]. It is future-proof and does not collide with your own variables.
Q82 web01 is in both prod and eu groups, and ntp_server has a different value on every run you check
Advanced
web01 is in both prod and eu groups, and ntp_server has a different value on every run you checkLikely causes โ Both groups define ntp_server. For groups at the same level, Ansible merges in alphabetical order, so the last one wins (prod beats eu). A child group beats its parent. A teammate adding a group named zz_* changes the result without anyone noticing.
Diagnose โ
ansible-inventory --host web01 --vars | jq .ntp_server
ansible-inventory --graph web01Fix โ Give one owner to each variable. To make the order explicit, use ansible_group_priority (higher wins; set it in inventory, not in group_vars):
eu:
vars:
ansible_group_priority: 10Prevent โ Design groups along separate dimensions (environment, region, role), and never define the same variable in two dimensions.
Q83 group_vars/prod.yml defines app_config: {log_level: warn} and the other keys from group_vars/all.yml disappear
Intermediate
group_vars/prod.yml defines app_config: {log_level: warn} and the other keys from group_vars/all.yml disappearLikely causes โ Dictionaries are replaced, not merged. The default hash_behaviour is replace, so the more specific app_config replaces the whole dictionary.
Fix โ Use separate names for each layer and merge them explicitly:
# all.yml
app_config_defaults: {log_level: info, workers: 4, port: 8080}
# prod.yml
app_config_overrides: {log_level: warn}
# role
app_config: "{{ app_config_defaults | combine(app_config_overrides | default({}), recursive=true) }}"Prevent โ Do not set hash_behaviour = merge globally. It is deprecated in spirit and changes behaviour everywhere. Prefer flat variables for values that need overriding.
Q84 With gather_facts: false, a template renders the host's old IP address from last week
Advanced
gather_facts: false, a template renders the host's old IP address from last weekLikely causes โ Fact caching is on (fact_caching = jsonfile or redis) with a long fact_caching_timeout. The host was rebuilt, but the cache still serves the old facts. set_fact: ... cacheable: true values also persist across runs.
Diagnose โ
ansible-config dump --only-changed | grep -i fact_caching
ls -l ~/.ansible/fact_cache/web01 # jsonfile backendFix โ Run once with --flush-cache, or delete that host's cache entry. Then gather fresh facts with ansible.builtin.setup for rebuilt hosts.
Prevent โ Set a sensible fact_caching_timeout (for example 3600โ86400 seconds). In immutable or auto-scaled fleets, prefer gathering = smart with a short timeout, and use cacheable only for values that are safe to keep.
Q85 A Jenkins job hangs forever at the start of ansible-playbook
Beginner
ansible-playbookLikely causes โ The play uses vars_prompt, or the run passes --ask-become-pass or --ask-vault-pass, and there is no terminal to answer the prompt.
Diagnose โ Run the same command locally and see whether it prompts. grep -rn vars_prompt playbooks/.
Fix โ Supply the values without prompting. A vars_prompt variable is skipped if it is passed with -e. Use --vault-password-file or a script, and put the become password in a vaulted ansible_become_password.
Prevent โ Make playbooks non-interactive by default, and add a CI timeout so a hang fails quickly.
Q86 Could not find or access 'prod.yml' Searched in: .../roles/app/vars/prod.yml ... from include_vars
Beginner
Could not find or access 'prod.yml' Searched in: .../roles/app/vars/prod.yml ... from include_varsLikely causes โ Relative paths in include_vars are resolved against the role's vars/ directory or the playbook's directory, not your current shell directory. The file may also be named after a value that does not exist ({{ env }}.yml with env unset or misspelled).
Diagnose โ The error lists every path it searched. Compare them with where the file actually is.
Fix โ Put the file in roles/app/vars/, or use "{{ playbook_dir }}/vars/{{ env }}.yml". For optional files, use the first_found lookup with a fallback:
- ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
vars:
params:
files: ["{{ env }}.yml", default.yml]
paths: ["{{ role_path }}/vars"]Prevent โ Validate env against an allowed list with assert before you use it in a path.
Q87 host_vars/web01.yml is ignored for one host
Beginner
host_vars/web01.yml is ignored for one hostLikely causes โ The host's inventory name is web01.example.com (or an IP address), and the host_vars filename has to match the inventory hostname exactly, not ansible_host or the short name.
Diagnose โ ansible-inventory --list | jq '._meta.hostvars | keys'
Fix โ Rename the file to host_vars/web01.example.com.yml, or change the inventory to use a short alias with ansible_host set:
web01 ansible_host=web01.example.comPrevent โ Use short, stable aliases as inventory names, and keep FQDNs and IPs in ansible_host.
Q88 [WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Beginner
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see detailsLikely causes โ Group names contain hyphens or dots (web-servers, eu-west-1). Group names must be valid Python identifiers to be safely usable in Jinja. This is common with dynamic inventory groups built from tags or regions.
Fix โ Rename the groups to web_servers. In dynamic inventories, rely on the plugins' default sanitising (TRANSFORM_INVALID_GROUP_CHARS) or set keyed_groups with a separator: "_".
Prevent โ Use snake_case group names. In templates, access groups as groups['web_servers'].
Q89 The generated upstream {} block contains web01 instead of IPs, and Nginx cannot resolve the names
Beginner
upstream {} block contains web01 instead of IPs, and Nginx cannot resolve the namesLikely causes โ The template uses inventory_hostname, which is the inventory alias. The address to connect to is ansible_host, and the real interface IP is a fact.
Fix โ
{% for h in groups['app'] %}
server {{ hostvars[h]['ansible_host'] | default(h) }}:8080;
{% endfor %}Or use hostvars[h]['ansible_facts']['default_ipv4']['address'] if facts for those hosts have been gathered.
Prevent โ Use inventory_hostname for labels and logs, and ansible_host or IP facts for network addresses.
Q90 A delegate_to: localhost task fails with /usr/bin/python3.9: No such file or directory
Advanced
delegate_to: localhost task fails with /usr/bin/python3.9: No such file or directoryLikely causes โ localhost is defined explicitly in the inventory, so it belongs to all and inherits ansible_python_interpreter: /usr/bin/python3.9 from group_vars/all.yml. That path exists on the targets, but not on the controller or in the execution environment.
Diagnose โ ansible-inventory --host localhost --vars | grep python
Fix โ
# host_vars/localhost.yml
ansible_connection: local
ansible_python_interpreter: "{{ ansible_playbook_python }}"Or remove localhost from the inventory and rely on implicit localhost, which already uses ansible_playbook_python.
Prevent โ Set the interpreter per OS group (rhel8, ubuntu), not in all.
Q91 A database migration with run_once: true ran four times in a rolling deploy with serial: 25%
Advanced
run_once: true ran four times in a rolling deploy with serial: 25%Likely causes โ run_once means once per batch. With serial, each batch is a separate pass through the play, so the task runs once per batch.
Fix โ Move one-time steps into their own play before the rolling play:
- name: Migrate once
hosts: app[0]
tasks:
- ansible.builtin.command: /opt/app/bin/migrate
- name: Rolling deploy
hosts: app
serial: "25%"
roles: [app]Or guard the task with when: inventory_hostname == ansible_play_hosts_all[0].
Prevent โ Make migrations idempotent (track a version in a migrations table), so that a repeated run is harmless anyway.
Q92 ERROR! Invalid extra vars data supplied. 'vars/prod.yml' could not be made into a dictionary
Beginner
ERROR! Invalid extra vars data supplied. 'vars/prod.yml' could not be made into a dictionaryLikely causes โ The file path was passed without @. -e vars/prod.yml is read as an inline string, not as a file.
Fix โ
ansible-playbook site.yml -e @vars/prod.ymlAlso check that the file's top level is a mapping, not a list.
Prevent โ Wrap the call in a Makefile or CI template so the flags stay consistent.
Q93 {{ proxy_url | default('http://proxy:3128') }} still renders as an empty string
Intermediate
{{ proxy_url | default('http://proxy:3128') }} still renders as an empty stringLikely causes โ default only fires when the variable is undefined. Here it is defined but empty (proxy_url: "" or null from an AWX survey or a group_vars placeholder).
Fix โ Pass true as the second argument, so falsy values also fall back to the default:
"{{ proxy_url | default('http://proxy:3128', true) }}"Prevent โ Do not define placeholder empty values in group_vars. Leave the variable undefined and keep defaults in the role.
Q94 A config file ends up containing __omit_place_holder__3f1c9e...
Advanced
__omit_place_holder__3f1c9e...Likely causes โ omit was used inside a larger string or a nested structure:
extra_args: "--timeout={{ timeout | default(omit) }}"omit only works when it is the entire value of a module parameter. Anywhere else, its placeholder string leaks into the output.
Fix โ Build the value conditionally:
extra_args: "{{ ('--timeout=' ~ timeout) if timeout is defined else '' }}"For dictionaries, filter out the unwanted keys (dict2items | rejectattr(...) | items2dict) instead of putting omit inside them.
Prevent โ Use default(omit) only at the top level of module arguments. Search rendered outputs in CI for __omit_place_holder__.
Q95 'ansible_mounts' is undefined after a "speed up facts" change
Intermediate
'ansible_mounts' is undefined after a "speed up facts" changeLikely causes โ gather_subset was reduced (for example to ['!all', 'min'] or ['!hardware']), and mounts, memory and devices are part of the hardware subset.
Diagnose โ ansible web01 -m setup -a 'gather_subset=!all,min' | grep -c mounts returns 0.
Fix โ Add back what the play needs:
gather_facts: true
gather_subset: [min, hardware]Or call ansible.builtin.setup with that subset right before the task that needs it.
Prevent โ Document which facts each role relies on, and test roles with the same gather_subset that production uses.
Q96 A custom fact in /etc/ansible/facts.d/app.fact does not appear under ansible_local
Intermediate
/etc/ansible/facts.d/app.fact does not appear under ansible_localLikely causes โ
- The file does not end in
.fact. - The file is a static JSON or INI file but has the executable bit set, so Ansible tries to run it.
- An executable fact prints something that is not JSON.
- Facts were gathered before the task that created the file.
Diagnose โ
ansible web01 -m setup -a 'filter=ansible_local'
ls -l /etc/ansible/facts.d/; /etc/ansible/facts.d/app.fact | jq . # if executableA broken file shows an error string under ansible_local.app instead of a dictionary.
Fix โ Use mode: "0644" for static facts and "0755" for scripts that print JSON. After deploying the file, refresh facts with ansible.builtin.setup: filter=ansible_local.
Prevent โ Ship custom facts in one role, together with a refresh task.
Q97 {{ ansible_env.HOME }} resolves to /root, and files land in the wrong home directory
Intermediate
{{ ansible_env.HOME }} resolves to /root, and files land in the wrong home directoryLikely causes โ Facts were gathered with become: true at play level, so the environment facts describe root. ansible_env is a snapshot from fact gathering, not from the current task's user.
Fix โ Look up the home directory of the user you actually mean:
- ansible.builtin.getent:
database: passwd
key: deploy
- ansible.builtin.set_fact:
deploy_home: "{{ ansible_facts.getent_passwd['deploy'][4] }}"Or use "~deploy" paths where the module expands ~.
Prevent โ Do not depend on ansible_env for paths. Make the user's home an explicit role variable.
Q98 could not locate file in lookup: /etc/app/settings.json
Intermediate
could not locate file in lookup: /etc/app/settings.jsonLikely causes โ Lookups (file, template, env, pipe) always run on the controller. The file exists on the remote host, not on the machine running Ansible.
Fix โ Read remote files with a module:
- ansible.builtin.slurp:
src: /etc/app/settings.json
register: raw
- ansible.builtin.set_fact:
settings: "{{ raw.content | b64decode | from_json }}"Use ansible.builtin.fetch to copy the file back to the controller.
Prevent โ Remember the rule: lookups and filters run locally, modules run remotely. The same applies to lookup('env', 'HOME'), which returns the controller's environment.
Q99 nginx_worker_processes is 8 on one host, and nobody knows where it is set
Intermediate
nginx_worker_processes is 8 on one host, and nobody knows where it is setLikely causes โ It is defined in one of more than 20 precedence layers: a role default, a role var, group_vars, host_vars, inventory, set_fact, include_vars, or extra vars.
Diagnose โ
ansible-inventory -i inventories/prod --host web07 --vars | jq .nginx_worker_processes
grep -rn 'nginx_worker_processes' inventories/ roles/ playbooks/
ansible -i inventories/prod web07 -m ansible.builtin.debug -a var=nginx_worker_processesIf inventory does not have it, check set_fact, include_vars and the AWX extra vars and surveys.
Fix โ Remove the stray definition, and keep the variable in one intended layer.
Prevent โ Prefix role variables with the role name, keep overrides in group_vars only, and check for duplicate definitions in code review.
Q100 [WARNING]: TASK: app : Configure vhost: The loop variable 'item' is already in use. You should set the loop_varvalue in theloop_control option for the task to something else to avoid variable collisions and unexpected behavior.
Intermediate
[WARNING]: TASK: app : Configure vhost: The loop variable 'item' is already in use. You should set the loop_varvalue in theloop_control option for the task to something else to avoid variable collisions and unexpected behavior.Likely causes โ An outer loop runs include_tasks or include_role, and the included file loops again. Both use item, so the inner loop shadows the outer one.
Fix โ
- ansible.builtin.include_tasks: vhost.yml
loop: "{{ sites }}"
loop_control:
loop_var: siteInside vhost.yml, refer to site.name and keep item for the inner loop.
Prevent โ Always set loop_var when looping over include_*. It also makes the included files easier to read.
Modules, Idempotency and Handlers
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q101 ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list
Beginner
ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers listLikely causes โ The name in notify: does not match the handler's name: exactly. The match is case- and space-sensitive (restart nginx against Restart nginx). Other causes: the handler lives in a different role that is not part of this play, or the role is loaded with include_role after the notify fires.
Diagnose โ
grep -rn -A1 'handlers' roles/nginx/handlers/main.yml
grep -rn 'notify' roles/ | grep -i nginxFix โ Make the names identical. Better, decouple them with listen:
# handlers/main.yml
- name: Restart nginx service
ansible.builtin.service: {name: nginx, state: restarted}
listen: nginx config changed
# task
notify: nginx config changedPrevent โ Use listen topics across roles. Molecule converge catches a missing handler immediately.
Q102 A handler named restart {{ app_service }} is never found when notified as restart myapp
Advanced
restart {{ app_service }} is never found when notified as restart myappLikely causes โ Handler names are templated once, when handlers are loaded, using only the variables available at that point (play vars, role defaults and vars, extra vars). If app_service comes from inventory, set_fact or include_vars, the name does not render the way you expect, and the notify does not match.
Fix โ Give the handler a static name, template the module arguments instead, and use listen:
- name: Restart application
ansible.builtin.systemd:
name: "{{ app_service }}"
state: restarted
listen: app restart neededPrevent โ Never template handler names or notify strings. Keep names static and parameters dynamic.
Q103 A command task reports changed on every run, and the Molecule idempotence check fails
Beginner
command task reports changed on every run, and the Molecule idempotence check failsLikely causes โ command and shell cannot know whether they changed anything, so they always report changed: true.
Fix โ Choose the option that fits:
# 1. Run only if an artifact is missing
- ansible.builtin.command: /opt/app/bin/init-db
args:
creates: /var/lib/app/.initialised
# 2. Read-only commands
- ansible.builtin.command: /opt/app/bin/app --version
register: v
changed_when: false
# 3. Decide from the output
- ansible.builtin.command: /opt/app/bin/migrate
register: m
changed_when: "'No migrations to apply' not in m.stdout"Prevent โ Prefer a real module when one exists. ansible-lint rule no-changed-when flags these tasks.
Q104 curl ... | tar xz fails on the host but the shell task reports success
Intermediate
curl ... | tar xz fails on the host but the shell task reports successLikely causes โ Without pipefail, a pipeline returns the exit code of its last command. curl can fail (404, DNS) while tar exits 0 on empty input, or the other way round.
Fix โ
- ansible.builtin.shell: |
set -o pipefail
curl -fsSL https://example.com/app.tgz | tar xz -C /opt/app
args:
executable: /bin/bash
creates: /opt/app/bin/app/bin/sh on Debian is dash, which only supports pipefail in recent versions, so set executable: /bin/bash. Even better, split the work into get_url and unarchive.
Prevent โ ansible-lint rule risky-shell-pipe flags pipelines without pipefail. Use curl -f so HTTP errors give a non-zero exit code.
Q105 lineinfile appends the same line again on every run
Intermediate
lineinfile appends the same line again on every runLikely causes โ regexp does not match the line that line writes. For example, the regexp is ^PermitRootLogin yes, the line written is PermitRootLogin no, so the next run finds no match and appends again. Without regexp, the comparison is on the exact line, so differences in whitespace also cause duplicates.
Diagnose โ grep -n PermitRootLogin /etc/ssh/sshd_config shows several copies.
Fix โ The regexp must match both the old and the new form:
- ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?\s*PermitRootLogin\s'
line: PermitRootLogin no
validate: /usr/sbin/sshd -t -f %sThen remove the existing duplicates once.
Prevent โ For anything more than a line or two, template the whole file or use *.d/ drop-in files.
Q106 lineinfile with backrefs: true reports ok but the line was never added
Intermediate
lineinfile with backrefs: true reports ok but the line was never addedLikely causes โ This is how backrefs works: if regexp matches nothing, the file is left unchanged, and no line is appended.
Fix โ Use two tasks (one to replace if present, one to add if missing), or drop backrefs and write the complete line:
- ansible.builtin.lineinfile:
path: /etc/default/grub
regexp: '^GRUB_CMDLINE_LINUX='
line: 'GRUB_CMDLINE_LINUX="quiet audit=1"'Prevent โ Only use backrefs when you are editing part of a line that you know already exists. Assert that it exists first if it matters.
Q107 A template task reports changed and restarts the service on every run
Intermediate
template task reports changed and restarts the service on every runLikely causes โ
- The template contains something that changes on every run:
{{ ansible_date_time.iso8601 }},now(), a random value, or{{ groups['web'] }}in non-deterministic order. - The file is modified after deployment by the application or another tool.
owner/group/modediffer from what the package resets on update.
Diagnose โ
ansible-playbook site.yml -l web01 --check --diff --tags nginxThe diff shows exactly which line changes.
Fix โ Remove the timestamps (use {{ ansible_managed }} without a date), sort lists (| sort), and seed random values (random(seed=inventory_hostname)).
Prevent โ Run each role twice in Molecule. A second run must show changed=0.
Q108 "msg": "Destination directory /etc/myapp does not exist"
Beginner
"msg": "Destination directory /etc/myapp does not exist"Likely causes โ copy and template do not create parent directories.
Fix โ
- ansible.builtin.file:
path: /etc/myapp
state: directory
owner: root
mode: "0755"
- ansible.builtin.template:
src: app.yml.j2
dest: /etc/myapp/app.ymlPrevent โ Order tasks as directories, then files, then services.
Q109 Could not find or access 'nginx.conf.j2' Searched in: .../roles/nginx/templates/nginx.conf.j2 ...
Beginner
Could not find or access 'nginx.conf.j2' Searched in: .../roles/nginx/templates/nginx.conf.j2 ...Likely causes โ The file sits in the wrong folder (for example roles/nginx/files/), the case differs, or src includes the folder name (templates/nginx.conf.j2), which some layouts tolerate but which breaks when the task is moved.
Diagnose โ The error lists every path Ansible searched. Compare them with find roles/nginx -name 'nginx.conf*'.
Fix โ Put templates in roles/<role>/templates/ and static files in roles/<role>/files/, and refer to them by filename only.
Prevent โ Use ansible-galaxy role init to create roles with the standard directory layout.
Q110 get_url fails with Request failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate>
Intermediate
get_url fails with Request failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate>Likely causes โ A corporate TLS-intercepting proxy or an internal CA (Artifactory, Nexus) whose root certificate is not in the target host's trust store. It can also be an old CA bundle on an old OS.
Diagnose โ
curl -v https://artifactory.internal/app.tgz
openssl s_client -connect artifactory.internal:443 -showcerts </dev/nullFix โ Install the CA on the hosts:
- ansible.builtin.copy:
src: corp-root-ca.crt
dest: /usr/local/share/ca-certificates/corp-root-ca.crt
notify: update ca trust # update-ca-certificates / update-ca-trustUse ca_path: on get_url and uri for one-off cases. Use validate_certs: false only in a lab, never in production.
Prevent โ Make CA trust part of the base role that runs first on every host.
Q111 unarchive fails with Failed to find handler for "/tmp/app.tar.gz". Make sure the required command to extract the file is installed.
Intermediate
unarchive fails with Failed to find handler for "/tmp/app.tar.gz". Make sure the required command to extract the file is installed.Likely causes โ The target is missing the tool needed to extract the archive (unzip for .zip, tar and gtar, zstd, xz), or the file is not a valid archive at all (an HTML error page saved as .tar.gz).
Diagnose โ file /tmp/app.tar.gz and which unzip tar on the target.
Fix โ Install the extractor first (package: name=unzip). Download with get_url and a checksum:, so a bad download fails before unarchive. Remember that remote_src: true is needed when the archive is already on the target.
Prevent โ List archive tools in the base role, and always verify checksums of downloaded artifacts.
Q112 template fails with "msg": "failed to validate" and nginx: [emerg] unknown directive "proxy_passs"
Intermediate
template fails with "msg": "failed to validate" and nginx: [emerg] unknown directive "proxy_passs"Likely causes โ validate: worked as designed: the rendered file failed the config test, so Ansible kept the old file in place. The bug is in the template or its variables.
Diagnose โ The stderr in the result shows the validator output. Render the template locally to inspect it.
Fix โ Fix the template. Keep the validation in place:
- ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
validate: nginx -t -c %s
notify: Reload nginxFor included snippets that cannot be tested alone, validate the whole config in a separate command: nginx -t before the handler runs.
Prevent โ Use validate on every config file that has a checker: sshd -t -f %s, visudo -cf %s, nginx -t, haproxy -c -f %s.
Q113 Unable to start service myapp: Job for myapp.service failed because the control process exited with error code.
Beginner
Unable to start service myapp: Job for myapp.service failed because the control process exited with error code.Likely causes โ The application itself fails to start (bad config, port in use, missing environment), or the unit file was changed but systemd was never reloaded, so it still runs the old definition.
Diagnose โ
ansible web01 -b -m command -a 'systemctl status myapp --no-pager'
ansible web01 -b -m command -a 'journalctl -u myapp -n 50 --no-pager'Fix โ Fix the application error shown in the journal. After changing a unit file, reload systemd:
- ansible.builtin.systemd:
name: myapp
state: started
enabled: true
daemon_reload: truePrevent โ Notify a handler with daemon_reload: true whenever a unit file changes, and add a health check (uri or wait_for) after starting.
Q114 uri fails with Status code was 401 and not [200]: HTTP Error 401: Unauthorized
Intermediate
uri fails with Status code was 401 and not [200]: HTTP Error 401: UnauthorizedLikely causes โ No credentials were sent, the token is wrong or expired, or the server expects preemptive Basic auth and uri waits for a 401 challenge that never comes.
Fix โ
- ansible.builtin.uri:
url: https://api.internal/v1/deploy
method: POST
url_username: "{{ api_user }}"
url_password: "{{ api_pass }}"
force_basic_auth: true
body_format: json
body: {version: "{{ app_version }}"}
status_code: [200, 201]
no_log: trueFor bearer tokens, use headers: {Authorization: "Bearer {{ token }}"}.
Prevent โ List every acceptable status_code explicitly, and keep tokens in Vault with no_log.
Q115 wait_for fails with Timeout when waiting for 127.0.0.1:8080 although the app is up
Intermediate
wait_for fails with Timeout when waiting for 127.0.0.1:8080 although the app is upLikely causes โ The application listens on another interface (only the private IP, or only ::1), on a different port, or takes longer to start than timeout allows. If the task has delegate_to: localhost, it checks the controller, not the host.
Diagnose โ ss -lntp | grep 8080 on the host.
Fix โ
- ansible.builtin.wait_for:
host: "{{ ansible_host }}"
port: 8080
timeout: 120
delegate_to: localhost # only if you mean "reachable from outside"For HTTP applications, prefer uri with until/retries against a health endpoint.
Prevent โ Make the bind address an explicit role variable, and check health rather than just whether a port is open.
Q116 "msg": "async task did not complete within the requested time - 300s"
Advanced
"msg": "async task did not complete within the requested time - 300s"Likely causes โ The job really took longer than async: 300 (a large backup, an OS upgrade), or it hangs waiting for input (apt prompting about a config file, a script waiting on stdin).
Diagnose โ Log in and look at the process. The async job's output is in ~/.ansible_async/<jid> of the become user.
Fix โ Fire the job and check on it separately, with a realistic upper bound:
- ansible.builtin.command: /opt/backup/run.sh
async: 3600
poll: 0
register: job
- ansible.builtin.async_status:
jid: "{{ job.ansible_job_id }}"
register: st
until: st.finished
retries: 120
delay: 30Make commands non-interactive (DEBIAN_FRONTEND=noninteractive, -y, </dev/null).
Prevent โ Use async for anything that runs longer than the SSH keepalive window, and clean up with async_status: mode=cleanup.
Q117 FAILED - RETRYING: [web01]: Wait for app health (5 retries left). ends in failure although the app is healthy
Intermediate
FAILED - RETRYING: [web01]: Wait for app health (5 retries left). ends in failure although the app is healthyLikely causes โ The until condition is wrong: it checks a key that does not exist, compares a string with an integer, or the task is missing register. Another cause is that uri itself fails on a non-200 code and never gets to evaluate until the way you expect.
Fix โ
- ansible.builtin.uri:
url: "http://{{ ansible_host }}:8080/health"
status_code: [200, 503]
return_content: true
register: health
until: health.status == 200 and (health.json.status | default('')) == 'UP'
retries: 20
delay: 6Prevent โ Run the task once with -vvv and copy the exact result keys into your condition.
Q118 --check fails with Could not find the requested service nginx on a fresh host
Intermediate
--check fails with Could not find the requested service nginx on a fresh hostLikely causes โ In check mode, the package install is only simulated. The next task tries to manage a service whose unit file does not exist yet, so it fails.
Fix โ Let dependent tasks tolerate check mode:
- ansible.builtin.service:
name: nginx
state: started
ignore_errors: "{{ ansible_check_mode }}"Or skip them with when: not ansible_check_mode.
Prevent โ Check mode is most useful against hosts that are already configured, for drift detection. Do not expect a clean dry run on a fresh host.
Q119 CI logs show database passwords in plain text after adding --diff
Advanced
--diffLikely causes โ --diff prints the before and after content of templated files, including secrets that were rendered from Vault. no_log hides the task result, but teams often forget it on templates.
Fix โ Rotate the leaked credentials. Then turn off the diff for sensitive files:
- ansible.builtin.template:
src: db.conf.j2
dest: /etc/app/db.conf
mode: "0600"
diff: false
no_log: trueScrub or expire the CI job logs.
Prevent โ Keep secrets in separate files rendered with diff: false, or load them at runtime from a secret manager. Audit for tasks that render vaulted variables without no_log.
Q120 A task fails with "censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"
Intermediate
"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"Likely causes โ no_log also hides the error message, so you cannot see why the task failed.
Fix โ Make no_log switchable for debugging, and run the debug pass only on a safe environment:
no_log: "{{ not (debug_secrets | default(false) | bool) }}"Then run -e debug_secrets=true -l staging-host. Alternatively, reproduce the call by hand on the host.
Prevent โ Put secret-handling tasks in small, separate tasks, so that no_log hides as little as possible. Validate inputs with assert before the sensitive task.
Q121 file: path=/var/www state=directory owner=www-data recurse=true takes minutes and shows changed
Intermediate
file: path=/var/www state=directory owner=www-data recurse=true takes minutes and shows changedLikely causes โ recurse: true walks every file under the directory. On large trees (uploads, node_modules) this is slow, and any file the application created with a different owner is reported as changed.
Fix โ Set ownership on the top-level directory only, and let the application create files with the right user (umask, a systemd User=). If a one-off recursive fix is needed, run it once behind a flag instead of on every run.
Prevent โ Avoid recurse: true in roles that run regularly. Deploy release directories that already have the correct ownership.
Q122 The user module reports changed on every run for the password parameter
Advanced
user module reports changed on every run for the password parameterLikely causes โ password_hash('sha512') generates a random salt each run, so the hash is always different from the one in /etc/shadow.
Fix โ Use a stable salt per host, or only set the password when the user is created:
- ansible.builtin.user:
name: deploy
password: "{{ deploy_password | password_hash('sha512', deploy_salt) }}"
update_password: on_create
no_log: trueHere deploy_salt is a fixed vaulted string of 16 characters or fewer ([./a-zA-Z0-9]).
Prevent โ Prefer SSH keys and disable passwords for service accounts. When passwords are required, store the pre-computed hash in Vault.
Q123 ignore_errors: true is set, but the play still aborts on that task
Advanced
ignore_errors: true is set, but the play still aborts on that taskLikely causes โ ignore_errors only covers a task that ran and returned failed. It does not cover unreachable hosts, undefined variables in the task's arguments, syntax errors or a missing module.
Fix โ
- For unreachable hosts, use
ignore_unreachable: true. - For undefined variables, add a
default(), or useblock/rescue, which catches most task-level errors:
- block:
- ansible.builtin.include_tasks: optional.yml
rescue:
- ansible.builtin.debug:
msg: "optional step failed: {{ ansible_failed_result.msg | default('n/a') }}"Prevent โ Prefer explicit failed_when conditions over blanket ignore_errors. ansible-lint flags ignore-errors usage.
Q124 failed_when with two conditions never fails although stderr contains ERROR
Intermediate
failed_when with two conditions never fails although stderr contains ERRORLikely causes โ A list under failed_when is combined with AND. All items must be true for the task to fail.
failed_when:
- result.rc != 0
- "'ERROR' in result.stderr" # both must be trueFix โ Use or explicitly:
failed_when: result.rc != 0 or 'ERROR' in result.stderrPrevent โ Write mixed conditions on one line with clear and/or and parentheses. Add a Molecule case that forces the failure.
Q125 Two blockinfile tasks on the same file keep overwriting each other
Intermediate
blockinfile tasks on the same file keep overwriting each otherLikely causes โ Both tasks use the default marker # {mark} ANSIBLE MANAGED BLOCK, so the second task replaces the block that the first one wrote, and the next run swaps them back.
Fix โ
- ansible.builtin.blockinfile:
path: /etc/hosts
marker: "# {mark} ANSIBLE MANAGED: internal services"
block: |
10.0.1.10 db.internalGive each block its own unique marker.
Prevent โ Always set marker explicitly. For more than one or two blocks, template the file or use drop-in directories.
Roles, Collections and Galaxy
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q126 ERROR! the role 'nginx' was not found in /home/ci/project/playbooks/roles:/home/ci/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/ci/project/playbooks
Beginner
ERROR! the role 'nginx' was not found in /home/ci/project/playbooks/roles:/home/ci/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/ci/project/playbooksLikely causes โ The role was never installed in CI (requirements.yml was not run), the playbook moved into a subfolder so roles/ is no longer next to it, or roles_path in ansible.cfg is not loaded.
Diagnose โ The error prints the exact search path. Run ansible --version to see which ansible.cfg is in use, and ansible-config dump | grep -i roles_path.
Fix โ
# ansible.cfg at repo root
[defaults]
roles_path = ./roles:./galaxy_rolesansible-galaxy role install -r requirements.yml -p galaxy_rolesPrevent โ Pin role sources in requirements.yml, and run the install step in every pipeline or bake it into the execution environment.
Q127 ERROR! couldn't resolve module/action 'community.docker.docker_container'. This often indicates a misspelling, missing collection, or incorrect module path.
Beginner
ERROR! couldn't resolve module/action 'community.docker.docker_container'. This often indicates a misspelling, missing collection, or incorrect module path.Likely causes โ The collection is not installed for the Python and Ansible being used. Typical situations: a minimal ansible-core install, a different virtualenv, or an execution environment that does not include it. A typo in the FQCN gives the same error.
Diagnose โ
ansible-galaxy collection list | grep -i docker
ansible-doc community.docker.docker_container | head -5
which ansible-playbook && ansible --versionFix โ
# collections/requirements.yml
collections:
- name: community.docker
version: ">=3.10.0,<5.0.0"ansible-galaxy collection install -r collections/requirements.ymlPrevent โ Keep a version-pinned collections/requirements.yml in the repo, and use it in CI, in AWX projects and in ansible-builder definitions.
Q128 [WARNING]: The specified collections path '/opt/collections' is not part of the configured Ansible collections paths ... The installed collection will not be picked up in an Ansible run
Intermediate
[WARNING]: The specified collections path '/opt/collections' is not part of the configured Ansible collections paths ... The installed collection will not be picked up in an Ansible runLikely causes โ The collection was installed with -p /opt/collections, but collections_path in ansible.cfg (or ANSIBLE_COLLECTIONS_PATH) does not include that folder.
Fix โ
[defaults]
collections_path = ./collections:~/.ansible/collections:/usr/share/ansible/collectionsOr install into a collections/ folder next to the playbook, which Ansible always searches.
Prevent โ Use one documented install path per project, and check with ansible-galaxy collection list in CI.
Q129 Unsupported parameters for (community.general.ufw) module: comment. Supported parameters include: ...
Intermediate
Unsupported parameters for (community.general.ufw) module: comment. Supported parameters include: ...Likely causes โ The parameter was added in a newer collection version than the one installed. The bundled ansible package may carry an older community.general than the docs you are reading. An indentation mistake that puts a task keyword under the module gives the same error.
Diagnose โ
ansible-galaxy collection list community.general
ansible-doc community.general.ufw | grep -A3 commentFix โ Upgrade the collection (ansible-galaxy collection install community.general --upgrade, or bump the version pin), or drop the parameter.
Prevent โ Read the docs matching your installed version (ansible-doc is always correct), and pin collection versions.
Q130 ERROR! Failed to resolve the requested dependencies map. Could not satisfy the following requirements: * community.general:>=12.0.0 (direct request)
Intermediate
ERROR! Failed to resolve the requested dependencies map. Could not satisfy the following requirements: * community.general:>=12.0.0 (direct request)Likely causes โ The version range does not exist on the configured Galaxy server, two requirements conflict (one collection pins <10, another needs >=12), or an internal mirror has not synced yet.
Diagnose โ
ansible-galaxy collection install -r requirements.yml -vvv
ansible-galaxy collection listLook at which server each version was looked up on.
Fix โ Relax or align the version ranges, or point server_list at a source that has the version. Use --force-with-deps only after you understand the conflict.
Prevent โ Update collection versions together in one pull request, and test the install in CI against the same Galaxy or Automation Hub servers production uses.
Q131 ERROR! Unknown error when attempting to call Galaxy at 'https://galaxy.ansible.com/api/': <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ...>
Intermediate
ERROR! Unknown error when attempting to call Galaxy at 'https://galaxy.ansible.com/api/': <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ...>Likely causes โ A corporate TLS-intercepting proxy, or a controller Python that does not trust the proxy's CA. It can also be a missing HTTPS_PROXY on a locked-down network.
Fix โ Add the corporate CA to the controller's trust store. Python uses certifi or the OS bundle depending on the install, so set SSL_CERT_FILE or REQUESTS_CA_BUNDLE if needed. Export HTTPS_PROXY. On restricted networks, mirror collections into a private Automation Hub or Galaxy NG. Use --ignore-certs only for a one-off test.
Prevent โ Build execution environments with the CA and the collections baked in, so runtime runs never call Galaxy.
Q132 Installing from Private Automation Hub fails with HTTP Code: 401, Message: Unauthorized
Intermediate
HTTP Code: 401, Message: UnauthorizedLikely causes โ The token is missing or expired, the URL points at the wrong repository (published or validated), or the server is not listed in server_list.
Fix โ
[galaxy]
server_list = private_hub, release_galaxy
[galaxy_server.private_hub]
url = https://hub.internal/api/galaxy/content/published/
token = <set via env instead>
[galaxy_server.release_galaxy]
url = https://galaxy.ansible.com/Supply the token through ANSIBLE_GALAXY_SERVER_PRIVATE_HUB_TOKEN from the CI secret store.
Prevent โ Use long-lived service tokens stored in a secret manager, never in the committed ansible.cfg.
Q133 A role installed from Git is not found by roles: [nginx]
Beginner
roles: [nginx]Likely causes โ Without a name:, the role takes the repository name (ansible-role-nginx), so nginx does not match.
Diagnose โ ansible-galaxy role list -p galaxy_roles
Fix โ
# requirements.yml
roles:
- name: nginx
src: git+https://github.com/acme/ansible-role-nginx.git
version: v2.3.1Prevent โ Always set name and pin version to a tag or commit in requirements.yml.
Q134 A role listed in meta/main.yml dependencies runs only once, even though two roles need it with different parameters
Intermediate
meta/main.yml dependencies runs only once, even though two roles need it with different parametersLikely causes โ Ansible deduplicates role dependencies. A role runs once per play unless it is called with different parameters or the role sets allow_duplicates: true. The opposite surprise also happens: a dependency runs twice because its parameters differ slightly.
Fix โ If running it several times is intended, add this to the dependency role:
# roles/firewall_rule/meta/main.yml
allow_duplicates: trueOtherwise, call it explicitly with include_role where it is needed.
Prevent โ Keep meta dependencies for true prerequisites. Make orchestration visible in the playbook instead of hiding it in dependency chains.
Q135 --tags nginx skips every task inside a role loaded with include_role, even though the include is tagged
Advanced
--tags nginx skips every task inside a role loaded with include_role, even though the include is taggedLikely causes โ Tags on a dynamic include_role or include_tasks apply only to the include statement itself, not to the tasks it loads. The include runs, but the tasks inside do not carry the nginx tag, so they are filtered out.
Fix โ
- ansible.builtin.include_role:
name: nginx
apply:
tags: [nginx]
tags: [nginx]Or use import_role, which is static and inherits tags to every task.
Prevent โ Use the rule: import_* when you need tags and --list-tasks, include_* when you need loops or runtime conditions. Check with ansible-playbook site.yml --tags nginx --list-tasks.
Q136 Half the tasks of an imported role are skipped after the first task runs
Advanced
Likely causes โ when on import_role or import_tasks is copied onto every task inside, and evaluated again for each one. If the role sets the variable used in the condition (for example when: not app_installed, and a task sets app_installed: true), the remaining tasks are skipped.
Fix โ Use a dynamic include so the condition is evaluated once:
- ansible.builtin.include_role:
name: app
when: not app_installedOr use a condition variable that the role does not change.
Prevent โ Do not let a role change the variables that gate it. Remember: imports copy the condition onto each task, includes evaluate it once.
Q137 Role B picks up listen_port: 9000 from role A, even though role B has its own default
Advanced
listen_port: 9000 from role A, even though role B has its own defaultLikely causes โ By default (private_role_vars = False), the vars/ and defaults/ of a role imported via roles: or import_role become visible to the rest of the play. Role A's vars/main.yml value outranks role B's defaults/.
Fix โ Prefix every role variable with its role name (rolea_listen_port, roleb_listen_port). If that is not possible, set:
[defaults]
private_role_vars = Trueor use include_role with public: false (the default for include_role).
Prevent โ Enforce var-naming[no-role-prefix] in ansible-lint.
Q138 The play stops at Validating arguments against arg spec main with missing required arguments: nginx_server_name
Intermediate
Validating arguments against arg spec main with missing required arguments: nginx_server_nameLikely causes โ The role has meta/argument_specs.yml, which marks nginx_server_name as required: true, and the caller did not provide it. This is the check doing its job.
Fix โ Pass the value through group_vars, vars: on the role, or include_role. If the argument should be optional, give it a default in both argument_specs.yml and defaults/main.yml.
argument_specs:
main:
options:
nginx_server_name:
type: str
required: true
description: Public hostname for the vhostPrevent โ Keep the specs and defaults in sync. ansible-doc -t role -r roles nginx shows the documented interface.
Q139 ERROR! [DEPRECATED]: ansible.builtin.include has been removed. Use include_tasks or import_tasks instead. after upgrading ansible-core
Beginner
ERROR! [DEPRECATED]: ansible.builtin.include has been removed. Use include_tasks or import_tasks instead. after upgrading ansible-coreLikely causes โ The bare include: keyword was removed in ansible-core 2.16. Old playbooks and Galaxy roles still use it.
Diagnose โ grep -rnE '^\s*-?\s*include:' playbooks/ roles/
Fix โ Use ansible.builtin.import_tasks for static use (tags and --list-tasks work), ansible.builtin.include_tasks for loops or dynamic filenames, and ansible.builtin.import_playbook at play level.
Prevent โ Before upgrading ansible-core, run the new version in CI with ansible-lint and treat deprecation warnings as failures.
Q140 [WARNING]: Collection community.general does not support Ansible version 2.15.13
Intermediate
[WARNING]: Collection community.general does not support Ansible version 2.15.13Likely causes โ The installed collection declares requires_ansible: ">=2.16.0" in meta/runtime.yml, but the controller or execution environment runs an older ansible-core. The modules may still load, but they can fail in subtle ways.
Diagnose โ ansible --version, ansible-galaxy collection list community.general
Fix โ Upgrade ansible-core, or pin the collection to the last version that supports your core version.
Prevent โ Pin ansible-core and the collections together in one execution environment definition, and upgrade them as a set.
Q141 Failed to import the required Python library (psycopg2) on db01's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location.
Intermediate
Failed to import the required Python library (psycopg2) on db01's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location.Likely causes โ Collection modules run on the target host and need their Python dependencies installed there, for the interpreter Ansible uses. It may be installed for a different Python (python3.11 against /usr/bin/python3).
Fix โ
- ansible.builtin.package:
name: python3-psycopg2
state: presentInstall it before any community.postgresql task, or set ansible_python_interpreter to the Python that has the library.
Prevent โ Give each role a "dependencies" task at the top that installs the module libraries it needs.
Q142 [WARNING]: Ansible is being run in a world writable directory (/vagrant), ignoring it as an ansible.cfg source.
Intermediate
[WARNING]: Ansible is being run in a world writable directory (/vagrant), ignoring it as an ansible.cfg source.Likely causes โ The project folder is world-writable (Vagrant shared folders, WSL /mnt/c, a mounted volume in CI). For security, Ansible refuses to load ansible.cfg from it, so roles_path, inventory and other settings are silently lost.
Fix โ Remove world-write permission (chmod o-w .), mount with proper permissions (for WSL, metadata mount options), or point to the file explicitly with export ANSIBLE_CONFIG=$PWD/ansible.cfg.
Prevent โ Check ansible --version for the line config file = ... at the start of CI jobs.
Q143 ansible-galaxy collection build rejects the collection name acme.web-tools
Beginner
ansible-galaxy collection build rejects the collection name acme.web-toolsLikely causes โ Collection namespaces and names may only contain lowercase letters, digits and underscores, and cannot start with a digit or an underscore. Hyphens are not allowed.
Fix โ In galaxy.yml, set namespace: acme and name: web_tools, and refer to content as acme.web_tools.<module>.
Prevent โ Scaffold with ansible-galaxy collection init acme.web_tools, which validates the name.
Q144 A role fails on Rocky Linux 9 with Could not find or access 'Rocky.yml' from an OS-specific include
Intermediate
Could not find or access 'Rocky.yml' from an OS-specific includeLikely causes โ The role includes {{ ansible_facts['distribution'] }}.yml, and only RedHat.yml, CentOS.yml and Ubuntu.yml exist.
Fix โ Fall back from the most specific file to the most generic:
- ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
vars:
params:
files:
- "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ ansible_facts['distribution'] }}.yml"
- "{{ ansible_facts['os_family'] }}.yml"
- default.yml
paths: ["{{ role_path }}/vars"]Prevent โ Key OS differences on os_family first, and test new distributions in the Molecule platform matrix.
Q145 A role fix is merged, but ansible-galaxy role install -r requirements.yml keeps running the old code
Beginner
ansible-galaxy role install -r requirements.yml keeps running the old codeLikely causes โ The role is already installed, and ansible-galaxy skips it with - nginx is already installed, skipping. unless the version changed or you force the install. Pinning a moving branch makes this worse.
Fix โ Bump the version: to the new tag, or run ansible-galaxy role install -r requirements.yml --force.
Prevent โ Pin roles to immutable tags or commits. In CI, install into a clean directory on every run.
Q146 A task under tasks: installs a prerequisite, but the role that needs it fails first
Beginner
tasks: installs a prerequisite, but the role that needs it fails firstLikely causes โ Play order is fixed: pre_tasks โ their handlers โ roles โ tasks โ their handlers โ post_tasks. Everything in roles: runs before tasks:, whatever order the file is written in.
Fix โ Move the prerequisite to pre_tasks, or place the role exactly where you need it with import_role inside tasks:.
Prevent โ In a play, use either roles: or tasks: with import_role, not both, so the order you read is the order that runs.
Q147 Collection installs started failing signature verification after --keyring was enabled in CI
Advanced
--keyring was enabled in CILikely causes โ The keyring is missing the publisher's public key (for example, the Red Hat or internal Automation Hub signing key), the keyring path in the CI image is wrong, or the server does not serve signatures for some collections. GALAXY_REQUIRED_VALID_SIGNATURE_COUNT then fails the install.
Diagnose โ
gpg --no-default-keyring --keyring ~/.ansible/pubring.kbx --list-keys
ansible-galaxy collection verify acme.web_tools --keyring ~/.ansible/pubring.kbx -vvvFix โ Import the correct signing key into the keyring that the CI image uses. Set GALAXY_REQUIRED_VALID_SIGNATURE_COUNT=+1 only for sources that sign everything. Use --ignore-signature-status-code only for specific known status codes, never as a blanket bypass.
Prevent โ Bake keys and the verification settings into the execution environment build, and verify during the build, not at runtime.
Q148 A custom collection module fails with Could not find imported module support code for ansible_collections.acme.app.plugins.modules.app_config. Looked for (['ansible.module_utils.app_helpers', ...])
Advanced
Could not find imported module support code for ansible_collections.acme.app.plugins.modules.app_config. Looked for (['ansible.module_utils.app_helpers', ...])Likely causes โ The module imports its helper the old, non-collection way (from ansible.module_utils.app_helpers import ...). Inside a collection, module_utils must be imported by their full collection path, so that AnsiballZ can bundle them.
Fix โ
from ansible_collections.acme.app.plugins.module_utils.app_helpers import render_configMake sure the file exists at plugins/module_utils/app_helpers.py, and rebuild and reinstall the collection.
Prevent โ Run ansible-test sanity and unit tests for every collection before publishing. They catch broken imports.
Q149 template error while templating string: No filter named 'to_slug' for your team's own filter
Advanced
template error while templating string: No filter named 'to_slug' for your team's own filterLikely causes โ
- The plugin lives in
filter_plugins/next to an old playbook location, but the playbook moved. - The plugin is in a role's
filter_plugins/, and that role is not part of this play. - The plugin is in a collection but is called without its FQCN.
- The Python file has a syntax error, so the plugin silently fails to load (visible with
-vvvv).
Diagnose โ
ansible-doc -t filter -l | grep -i slug
ANSIBLE_FILTER_PLUGINS=./filter_plugins ansible localhost -m debug -a "msg={{ 'A B' | to_slug }}" -vvvvFix โ Ship custom plugins in a collection and call them as acme.utils.to_slug, or set filter_plugins = ./plugins/filter in ansible.cfg.
Prevent โ Keep custom plugins in a versioned collection with tests (ansible-test units).
Q150 An outdated copy of the common role runs instead of the one in the repo
Advanced
common role runs instead of the one in the repoLikely causes โ Roles are found by name, and the first match wins. If the playbook moved and the project's roles/ is no longer next to it, or roles_path lists ~/.ansible/roles first, a stale common installed months ago shadows the repo copy.
Diagnose โ
- ansible.builtin.debug:
var: role_path # inside the role: shows which copy is usedls ~/.ansible/roles /etc/ansible/roles for leftover copies.
Fix โ Remove the stale copies, put the project's role directories first in roles_path, and give internal roles unique names, or better, ship them in a collection (acme.platform.common) so the FQCN removes the ambiguity.
Prevent โ Run CI in clean containers or execution environments with no user-level role directories.
Vault, Performance and Execution Behaviour
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q151 ERROR! Attempting to decrypt but no vault secrets found
Beginner
ERROR! Attempting to decrypt but no vault secrets foundLikely causes โ The playbook loads a vaulted file or an !vault variable, and no password was supplied: no --ask-vault-pass, --vault-password-file or --vault-id, and no vault_password_file in ansible.cfg.
Fix โ
ansible-playbook site.yml --vault-id prod@~/.secrets/prod.pass
# or in CI
ANSIBLE_VAULT_PASSWORD_FILE=/run/secrets/vault_pass ansible-playbook site.ymlPrevent โ Set vault_identity_list in the project ansible.cfg, pointing at password files that CI and developers create outside the repo.
Q152 ERROR! Decryption failed (no vault secrets were found that could decrypt) on inventories/prod/group_vars/all/vault.yml
Beginner
ERROR! Decryption failed (no vault secrets were found that could decrypt) on inventories/prod/group_vars/all/vault.ymlLikely causes โ A password was supplied but it is the wrong one, for example the staging password used for a prod file. Another cause is a password file with a trailing newline or extra characters. Ansible strips one trailing newline, but not \r\n from Windows editors.
Diagnose โ
head -1 inventories/prod/group_vars/all/vault.yml # $ANSIBLE_VAULT;1.2;AES256;prod
ansible-vault view --vault-id prod@prompt inventories/prod/group_vars/all/vault.yml
od -c ~/.secrets/prod.pass | tail -2 # look for \rFix โ Use the correct password for that environment, and remove the stray \r with dos2unix.
Prevent โ Use one vault ID per environment, with IDs that match the inventory directories.
Q153 Both --vault-id [email protected] and --vault-id prod@prompt are passed, and prod files still fail to decrypt
Intermediate
--vault-id [email protected] and --vault-id prod@prompt are passed, and prod files still fail to decryptLikely causes โ The vault ID label is only a hint. Ansible tries every supplied secret, so a failure means none of them is right. The file was probably encrypted with a different password than the one now called "prod", for example by someone who forgot --encrypt-vault-id. With vault_id_match = True, only the secret whose label matches the file header is tried.
Diagnose โ head -1 on the file shows the label it was encrypted with. If it has no label (1.1 format), it was encrypted without an ID.
Fix โ Re-key the file to the correct ID:
ansible-vault rekey --vault-id old@prompt --new-vault-id prod@prompt file.ymlPrevent โ Set encrypt_vault_id = prod in each environment's ansible.cfg, or wrap encryption in a script that always passes --encrypt-vault-id.
Q154 Vault format unhexlify error: Odd-length string after pasting an encrypt_string value
Intermediate
Vault format unhexlify error: Odd-length string after pasting an encrypt_string valueLikely causes โ The !vault | block was damaged when pasted: lines re-wrapped, a line dropped, inconsistent indentation, or the trailing digits cut off. Non-hexadecimal digit found points to the same problem.
Fix โ Generate the value again and paste it as one block:
ansible-vault encrypt_string --vault-id prod@prompt --stdin-name db_passworddb_password: !vault |
$ANSIBLE_VAULT;1.2;AES256;prod
6233... # every line indented the same, no editsCheck with ansible localhost -m debug -a var=db_password -e @file.yml --vault-id prod@prompt.
Prevent โ For many secrets, prefer whole-file encryption (vault.yml), which cannot be mangled by YAML indentation.
Q155 Problem running vault password script /home/ci/.vault_pass ([Errno 8] Exec format error). If this is not a script, remove the executable bit from the file.
Advanced
Problem running vault password script /home/ci/.vault_pass ([Errno 8] Exec format error). If this is not a script, remove the executable bit from the file.Likely causes โ If a vault password file is executable, Ansible runs it and uses its stdout as the password. A plain text file that ended up chmod +x (common when copied from Windows or by a CI secret mount) is executed and fails.
Fix โ For a plain password file, run chmod 600 ~/.vault_pass. For a real script (for example one fetching from AWS Secrets Manager), give it a shebang, make it print only the password, and exit 0:
#!/usr/bin/env bash
aws secretsmanager get-secret-value --secret-id ansible/vault/prod \
--query SecretString --output textScripts named *-client (for example vault-pass-client.py) also receive --vault-id <label>.
Prevent โ Check the file mode in CI, and keep the password retrieval logic in a reviewed script.
Q156 Every change to vault.yml produces an unreadable diff and constant merge conflicts
Intermediate
vault.yml produces an unreadable diff and constant merge conflictsLikely causes โ Encrypted files change completely on every edit, because each encryption uses a new salt. Two people editing the same vault file at the same time always conflict.
Fix โ Get readable local diffs with a textconv:
echo '*vault*.yml diff=ansible-vault' >> .gitattributes
git config diff.ansible-vault.textconv "ansible-vault view"To resolve a conflict, view both versions, merge the plaintext by hand, and encrypt again.
Prevent โ Keep vault files small and split them per environment and per role. Consider an external secret manager for secrets that change often.
Q157 Vaulted variables are undefined, although the file decrypts fine with ansible-vault view
Beginner
ansible-vault viewLikely causes โ The vault file is not where Ansible loads variables from. It sits at group_vars/prod/secrets/vault.yml (too deep is fine), or at vars/vault.yml (never loaded automatically), or it is named after a group that does not exist.
Fix โ Use the standard pattern:
inventories/prod/group_vars/all/vars.yml # db_password: "{{ vault_db_password }}"
inventories/prod/group_vars/all/vault.yml # vault_db_password: ... (encrypted)Or load it explicitly with vars_files.
Prevent โ Use the vault_ prefix and indirection pattern, so grep can always find where a secret is used.
Q158 On 300 hosts, every task seems to run in batches of five
Beginner
Likely causes โ The default forks is 5. Ansible only talks to five hosts at a time per task.
Diagnose โ ansible-config dump | grep -i forks
Fix โ
[defaults]
forks = 50Size this to the controller's CPU and memory. Every fork is a Python process.
Prevent โ Set forks in the project's ansible.cfg, and measure with callbacks_enabled = ansible.posix.profile_tasks, ansible.posix.timer.
Q159 pipelining = True was turned on, but runs are no faster
Intermediate
pipelining = True was turned on, but runs are no fasterLikely causes โ The setting is not applied (wrong section or wrong config file), the connection plugin does not use it, or a become method that needs a tty disables it. Some modules, such as copy and template, still need file transfers.
Diagnose โ
ansible-config dump --only-changed | grep -i pipelining
ansible web01 -m ping -vvvv | grep -cE 'PUT|sftp'With pipelining active, simple modules show no PUT of the AnsiballZ file.
Fix โ Put the setting in the [ssh_connection] (or [connection]) section of the ansible.cfg that is actually in use, and make sure requiretty is not set in sudoers.
Prevent โ Benchmark changes with profile_tasks before and after, instead of guessing.
Q160 ERROR! A worker was found in a dead state
Advanced
ERROR! A worker was found in a dead stateLikely causes โ A fork process died, usually because the Linux OOM killer stopped it. Typical triggers are high forks, huge registered results (a find across /, slurp of large files), large fact sets, or a container controller with a low memory limit.
Diagnose โ
dmesg -T | grep -i -E 'killed process|oom'
kubectl describe pod <awx-job-pod> | grep -i OOMKilled # AWXFix โ Lower forks, avoid registering big outputs (filter on the target, use changed_when and short stdout), use gather_subset to cut facts, and give the controller or AWX job pod more memory.
Prevent โ Set memory requests and limits for execution nodes based on measured peaks, and watch controller memory during large runs.
Q161 With strategy: free, a task that reads hostvars['db01'].db_ready fails on some runs
Advanced
strategy: free, a task that reads hostvars['db01'].db_ready fails on some runsLikely causes โ free lets each host run ahead on its own, so a web host can reach its task before db01 has set db_ready. With the default linear strategy, every host finishes task N before any host starts task N+1.
Fix โ Split the work into separate plays (database first, then web), or keep the play linear. Use free only for plays whose hosts do not depend on each other.
Prevent โ Treat cross-host dependencies (hostvars, delegate_to another inventory host, run_once results) as a sign that free is not appropriate.
Q162 The rolling deploy stops after the second batch with NO MORE HOSTS LEFT
Intermediate
NO MORE HOSTS LEFTLikely causes โ Every host in the batch failed, or max_fail_percentage was exceeded, or any_errors_fatal: true was triggered. Ansible then ends the play, and later batches never start. That is intentional.
Diagnose โ Scroll up to the first fatal: in the failing batch, and check the PLAY RECAP for failed= and unreachable=.
Fix โ Fix the cause on the failed hosts, then continue with only the hosts that are not yet updated:
ansible-playbook deploy.yml --limit 'app:!app-0[1-4]'Prevent โ Add a health check at the end of each batch so a bad release stops early. Write deploys so that a re-run on already-updated hosts is a no-op.
Q163 A run failed, but there is no .retry file to re-run only the failed hosts
Beginner
.retry file to re-run only the failed hostsLikely causes โ retry_files_enabled has defaulted to False since Ansible 2.8.
Fix โ
[defaults]
retry_files_enabled = True
retry_files_save_path = ~/.ansible/retryThen run ansible-playbook site.yml --limit @~/.ansible/retry/site.retry. Alternatively, copy the failed hosts from the recap into --limit.
Prevent โ In AWX or CI, use the "relaunch on failed hosts" feature, or make plays idempotent so a full re-run is safe.
Q164 --start-at-task "Deploy app" fails with 'artifact_url' is undefined
Intermediate
--start-at-task "Deploy app" fails with 'artifact_url' is undefinedLikely causes โ --start-at-task skips everything before that task, including the set_fact, register or include_vars tasks that define later variables.
Fix โ Tag the tasks that define variables with always, so they run even when skipped over:
- ansible.builtin.set_fact:
artifact_url: "{{ repo_url }}/{{ app_version }}/app.tgz"
tags: [always]Alternatively, use --tags deploy with well-tagged roles instead of --start-at-task.
Prevent โ Compute derived variables in vars or defaults (evaluated lazily) instead of in set_fact where possible.
Q165 --tags deploy also ran a cleanup task tagged always and deleted the release directory
Intermediate
--tags deploy also ran a cleanup task tagged always and deleted the release directoryLikely causes โ Tasks tagged always run for any --tags selection, and are skipped only with --skip-tags always. The never tag works the opposite way: those tasks run only when their other tag is requested explicitly.
Fix โ Remove always from destructive tasks, and give them never plus an explicit tag:
- ansible.builtin.file:
path: /opt/app/releases/old
state: absent
tags: [never, cleanup]Now it only runs with --tags cleanup.
Prevent โ Keep always for fact-setting and validation tasks only. Review --list-tasks --tags <x> output before relying on a tag.
Q166 After an upgrade: ERROR! Your Ansible version (2.17.x) is too recent. The most recent version supported by Mitogen for Ansible is ...
Advanced
ERROR! Your Ansible version (2.17.x) is too recent. The most recent version supported by Mitogen for Ansible is ...Likely causes โ The Mitogen strategy plugin is enabled (strategy = mitogen_linear) and its release does not support the new ansible-core yet. Mitogen hooks into private internals, so it often lags behind core releases.
Fix โ Upgrade Mitogen to a release that supports your ansible-core, or remove strategy_plugins and strategy = mitogen_* from ansible.cfg and make up the speed with pipelining, ControlPersist, higher forks and fewer tasks.
Prevent โ Treat Mitogen as an optional accelerator. Pin it together with ansible-core, and test upgrades in CI before rolling them to controllers.
Q167 A role that runs include_tasks in a loop over 3,000 firewall rules takes 40 minutes
Advanced
include_tasks in a loop over 3,000 firewall rules takes 40 minutesLikely causes โ Each loop iteration of include_tasks is processed per host: templating, a task object for each item, and a separate module run with its own SSH round trip. With thousands of items, the overhead dominates.
Fix โ Push the loop down to the target:
- Template a full ruleset file (
nftables.conf, iptables-restore format) once, and apply it with a handler. - Use modules that accept lists, such as
packagewith a list of names. - If you must loop, loop over a module directly instead of over
include_tasks.
Prevent โ Profile with profile_tasks, and treat any task with more than a few hundred iterations as a sign the design needs to change.
Q168 ERROR! Invalid callback for stdout specified: yaml after rebuilding the controller
Beginner
ERROR! Invalid callback for stdout specified: yaml after rebuilding the controllerLikely causes โ stdout_callback = yaml relied on the community.general.yaml callback, which is missing in a minimal ansible-core install, and is deprecated in favour of the built-in result format option.
Fix โ
[defaults]
stdout_callback = ansible.builtin.default
callback_result_format = yamlPrevent โ Prefer built-in options over collection callbacks for core behaviour, and keep ansible.cfg in the repo, reviewed like code.
Q169 A setting in your ansible.cfg has no effect
Beginner
ansible.cfg has no effectLikely causes โ Another config file wins. Ansible uses the first file it finds and never merges them: ANSIBLE_CONFIG, then ./ansible.cfg, then ~/.ansible.cfg, then /etc/ansible/ansible.cfg. An environment variable such as ANSIBLE_FORKS overrides the file. The setting may also be in the wrong [section].
Diagnose โ
ansible --version | grep 'config file'
ansible-config dump --only-changed
env | grep ^ANSIBLE_Fix โ Run from the project root, or export ANSIBLE_CONFIG. Move the key into the section that ansible-config list documents for it.
Prevent โ Start CI jobs by printing ansible --version and ansible-config dump --only-changed.
Q170 ERROR! Unexpected Exception, this is probably a bug: cannot import name 'environmentfilter' from 'jinja2'
Advanced
ERROR! Unexpected Exception, this is probably a bug: cannot import name 'environmentfilter' from 'jinja2'Likely causes โ An old Ansible (2.9 or 2.10) runs with Jinja2 3.1 or newer, which removed environmentfilter. This usually happens after pip install -U pulled new dependencies into a shared environment.
Diagnose โ ansible --version shows the Python path. Then run <that python> -m pip show jinja2 ansible-core.
Fix โ The real fix is to upgrade to a supported ansible-core. As a stopgap, pin jinja2<3.1 in that virtualenv.
Prevent โ Run Ansible from a dedicated virtualenv or execution environment with locked dependencies (pip-compile, an EE image tag), never from the system Python.
Q171 ERROR: Ansible requires the locale encoding to be UTF-8; Detected ISO8859-1.
Beginner
ERROR: Ansible requires the locale encoding to be UTF-8; Detected ISO8859-1.Likely causes โ Since ansible-core 2.14, the controller refuses to run under a non-UTF-8 locale. This is common in minimal containers, cron jobs and CI runners with LANG unset.
Fix โ
export LANG=C.UTF-8 LC_ALL=C.UTF-8Set these in the Dockerfile ENV, in the CI job environment, or in the cron entry.
Prevent โ Set the locale in your controller and execution environment images.
Q172 Packages got installed on the CI runner, and every "host" in the output reports the runner's hostname
Intermediate
Likely causes โ connection: local (play level) or ansible_connection: local (in group_vars/all) was copied from an API-only playbook. Every task now runs on the controller once per inventory host.
Diagnose โ
ansible-inventory --host web01 --vars | grep ansible_connection
grep -rn 'connection: local' playbooks/Fix โ Remove the setting, and for API tasks use delegate_to: localhost (or hosts: localhost) only where it is needed. Then clean up the runner.
Prevent โ Run CI on ephemeral runners, and add an assert that ansible_facts['hostname'] matches the expected pattern in sensitive roles.
Q173 An uri call to the CMDB returns HTTP Error 429: Too Many Requests for most hosts
Intermediate
uri call to the CMDB returns HTTP Error 429: Too Many Requests for most hostsLikely causes โ With forks: 50, fifty hosts hit the API at the same moment, and the API rate-limits.
Fix โ
- ansible.builtin.uri:
url: https://cmdb.internal/api/hosts/{{ inventory_hostname }}
delegate_to: localhost
throttle: 5
register: cmdb
until: cmdb.status != 429
retries: 5
delay: 10throttle limits only this task, without slowing the rest of the play.
Prevent โ Use throttle for shared external dependencies (APIs, license servers, package mirrors), or make one bulk API call with run_once.
Q174 Copying a 4 GB artifact with copy takes 20 minutes per host and sometimes times out
Intermediate
copy takes 20 minutes per host and sometimes times outLikely causes โ copy checksums the file on both sides and pushes it from the controller over SSH to every host, so the controller's uplink becomes the bottleneck.
Fix โ Have the targets pull the artifact instead:
- ansible.builtin.get_url:
url: "https://artifacts.internal/app/{{ app_version }}/app.tar.gz"
dest: /opt/app/app.tar.gz
checksum: "sha256:{{ app_sha256 }}"For directory trees, use ansible.posix.synchronize, which needs rsync on both ends.
Prevent โ Store artifacts in a repository (S3, Artifactory, Nexus) close to the hosts. Do not ship large binaries from the controller.
Q175 Runs on the controller start failing with [Errno 28] No space left on device
Intermediate
[Errno 28] No space left on deviceLikely causes โ Something fills the controller's disk over time: a growing log_path file, a jsonfile fact cache for thousands of hosts, fetch tasks that download files on every run, or leftover ~/.ansible/tmp directories from killed runs.
Diagnose โ
df -h ~ /tmp
du -sh ~/.ansible/* /var/log/ansible.log 2>/dev/nullFix โ Clean up and rotate: add a logrotate rule for the Ansible log, prune the fact cache, and set fetch destinations under a directory that is cleaned. Remove stale ~/.ansible/tmp/ansible-local-* directories.
Prevent โ Run controllers ephemerally (CI containers, AWX execution environments), or monitor disk usage on long-lived controllers.
Cloud, AWX, Windows and Molecule
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q176 Failed to import the required Python library (botocore and boto3) on web01's Python /usr/bin/python3.
Beginner
Failed to import the required Python library (botocore and boto3) on web01's Python /usr/bin/python3.Likely causes โ AWS modules (amazon.aws.*) run wherever the task runs. Here the task ran on the managed host web01, which has no boto3. Normally AWS API calls should run on the controller, with hosts: localhost or delegate_to: localhost. When they do run there, the controller's Python (or virtualenv, or EE) may be missing boto3.
Diagnose โ The message names the host and the interpreter. Check with "{{ ansible_playbook_python }}" -c 'import boto3, botocore'.
Fix โ
- hosts: localhost
connection: local
gather_facts: false
tasks:
- amazon.aws.ec2_instance_info:
region: ap-south-1
filters: {"tag:Env": prod}Then pip install boto3 botocore into the controller environment.
Prevent โ Build boto3 into the execution environment (requirements.txt in ansible-builder), and keep API plays on localhost.
Q177 [WARNING]: * Failed to parse inventory/aws.yml with auto plugin: inventory source 'inventory/aws.yml' could not be verified by inventory plugin 'amazon.aws.aws_ec2'
Intermediate
[WARNING]: * Failed to parse inventory/aws.yml with auto plugin: inventory source 'inventory/aws.yml' could not be verified by inventory plugin 'amazon.aws.aws_ec2'Likely causes โ The aws_ec2 plugin only accepts files whose names end in aws_ec2.yml or aws_ec2.yaml. It can also fail if the collection is not installed, or if enable_plugins in ansible.cfg excludes auto and amazon.aws.aws_ec2.
Fix โ Rename the file to inventory/prod.aws_ec2.yml:
plugin: amazon.aws.aws_ec2
regions: [ap-south-1]
filters:
instance-state-name: running
"tag:Env": prodTest it with ansible-inventory -i inventory/prod.aws_ec2.yml --graph.
Prevent โ Use the naming convention <env>.aws_ec2.yml, and check the inventory with ansible-inventory --graph in CI.
Q178 The aws_ec2 inventory parses without errors but returns zero hosts
Intermediate
aws_ec2 inventory parses without errors but returns zero hostsLikely causes โ
- The wrong
regions. - A tag filter with the wrong case (
tag:envagainsttag:Env). - The wrong AWS account or profile.
- Instances that are stopped while the filter asks for
running. - A stale inventory cache (
cache: true).
Diagnose โ
aws sts get-caller-identity
aws ec2 describe-instances --region ap-south-1 --filters "Name=tag:Env,Values=prod" --query 'Reservations[].Instances[].InstanceId'
ansible-inventory -i prod.aws_ec2.yml --list -vvv | head -50Fix โ Align the filters with what the AWS CLI returns, set profile: or the environment credentials for the right account, and refresh with --flush-cache if caching is on.
Prevent โ Standardise tag keys (for example Env, Role) enforced by Terraform or AWS Config, and alert when a key group comes back empty.
Q179 Failed to describe instances: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation or (ExpiredToken)
Intermediate
Failed to describe instances: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation or (ExpiredToken)Likely causes โ The IAM identity lacks ec2:DescribeInstances (and ec2:DescribeRegions if regions is not set), an SSO or STS session expired, or the controller is picking up stale keys from ~/.aws/credentials before its instance role.
Diagnose โ
aws sts get-caller-identity
env | grep ^AWS_Fix โ Grant read-only EC2 describe permissions to the automation role, refresh the session (aws sso login --profile prod), or remove the stale static keys so the instance or IRSA role is used.
Prevent โ In CI and AWX, use short-lived role credentials (OIDC to AWS, instance profiles, IRSA) instead of static access keys.
Q180 Dynamic inventory finds the instances, but every host is UNREACHABLE
Intermediate
UNREACHABLELikely causes โ By default, the plugin names hosts by public DNS. Private-subnet instances have no public DNS, or the controller cannot route to it. Ansible then tries to connect to an address that does not work.
Diagnose โ ansible-inventory -i prod.aws_ec2.yml --host <name> | jq '.ansible_host, .private_ip_address, .public_dns_name'
Fix โ
hostnames:
- tag:Name
- private-ip-address
compose:
ansible_host: private_ip_addressRun from inside the VPC, or go through a bastion (ProxyJump) or SSM.
Prevent โ Use readable names for hosts (tag:Name) and keep connection addresses in compose.
Q181 Using the SSM connection plugin fails with SessionManagerPlugin is not found or hangs on file transfer
Advanced
SessionManagerPlugin is not found or hangs on file transferLikely causes โ
- The AWS
session-manager-pluginbinary is not installed on the controller or in the EE. - No
ansible_aws_ssm_bucket_nameis set. The plugin moves module files through S3, so a bucket is required. - The instance role lacks
AmazonSSMManagedInstanceCoreor access to that bucket. - The bucket is in a different region than the instance.
Diagnose โ
session-manager-plugin --version
aws ssm describe-instance-information --query 'InstanceInformationList[].InstanceId'Fix โ
ansible_connection: amazon.aws.aws_ssm # community.aws.aws_ssm on older collections
ansible_aws_ssm_region: ap-south-1
ansible_aws_ssm_bucket_name: acme-ansible-ssm-ap-south-1Install the plugin into the EE image, and grant the instance role s3:GetObject and s3:PutObject on the bucket.
Prevent โ Provision the bucket, the IAM roles and the SSM agent with Terraform as part of the base image or module.
Q182 winrm or requests is not installed: No module named 'winrm'
Beginner
winrm or requests is not installed: No module named 'winrm'Likely causes โ The controller's Python lacks pywinrm. Windows hosts run modules over WinRM, and the client library is on the controller side.
Fix โ
pip install "pywinrm>=0.4" # add [kerberos] or [credssp] extras as neededInstall it into the same environment ansible-playbook uses (check ansible --version for the Python path) or into the EE.
Prevent โ Keep pywinrm (and pypsrp if you use psrp) in the EE's requirements.txt.
Q183 ntlm: HTTPSConnectionPool(host='win01', port=5986): Max retries exceeded with url: /wsman (Caused by SSLError(SSLCertVerificationError(...)))
Intermediate
ntlm: HTTPSConnectionPool(host='win01', port=5986): Max retries exceeded with url: /wsman (Caused by SSLError(SSLCertVerificationError(...)))Likely causes โ The WinRM HTTPS listener uses a self-signed certificate, or a certificate from an internal CA that the controller does not trust, or a certificate whose CN does not match the name you connect with.
Fix โ In production, issue listener certificates from the internal CA (through AD CS auto-enrolment) and trust that CA:
ansible_winrm_ca_trust_path: /etc/pki/tls/certs/corp-root-ca.pemIn a lab only, use ansible_winrm_server_cert_validation: ignore.
Prevent โ Automate listener certificate provisioning with GPO or a bootstrap script, and connect by FQDN matching the certificate.
Q184 ntlm: the specified credentials were rejected by the server
Intermediate
ntlm: the specified credentials were rejected by the serverLikely causes โ The wrong username format, a wrong or expired password, a locked account, or the user is not in a group allowed to use WinRM (local Administrators or Remote Management Users). With basic transport, only local accounts work, and only over HTTPS or with AllowUnencrypted.
Diagnose โ Test from another Windows host: Test-WSMan win01 -Credential (Get-Credential) -Authentication Negotiate.
Fix โ Use ansible_user: [email protected] with Kerberos, or CORP\svc_ansible with NTLM. Unlock the account or reset the password, and add it to the right local group.
Prevent โ Use a dedicated domain service account managed by GPO, with its password stored in Vault or an AWX credential and rotated regularly.
Q185 kerberos: authGSSClientStep() failed: (('Unspecified GSS failure. Minor code may provide more information', 851968), ('Server not found in Kerberos database', -1765328377))
Advanced
kerberos: authGSSClientStep() failed: (('Unspecified GSS failure. Minor code may provide more information', 851968), ('Server not found in Kerberos database', -1765328377))Likely causes โ Kerberos needs the service principal HTTP/<fqdn>. Connecting by IP address or short name, a broken reverse DNS entry, or a host in a different realm means the KDC cannot find the principal.
Diagnose โ
kinit [email protected] && klist
kvno HTTP/win01.corp.example.com
host win01.corp.example.com; host <its IP>Fix โ Set ansible_host to the FQDN. Fix DNS (forward and reverse). Make sure /etc/krb5.conf has the realm in uppercase, with correct kdc and domain_realm mappings.
Prevent โ Use the FQDN in inventory for Windows hosts, and add a CI test that runs kinit and a win_ping against one known host.
Q186 The powershell shell family is incompatible with the sudo become plugin
Intermediate
The powershell shell family is incompatible with the sudo become pluginLikely causes โ become: true with the default sudo method was inherited by Windows hosts, usually from group_vars/all or play-level settings shared with Linux.
Fix โ
# group_vars/windows.yml
ansible_connection: winrm
ansible_shell_type: powershell
ansible_become_method: runas
ansible_become_user: SYSTEM # only where elevation is really neededBetter, do not set become for Windows plays at all unless a task needs it.
Prevent โ Keep separate plays and group variables for Linux and Windows, and do not put connection or become settings in all.
Q187 A Windows task that copies from \\fileserver\share fails with Access is denied, although the same account works over RDP
Advanced
\\fileserver\share fails with Access is denied, although the same account works over RDPLikely causes โ This is the Kerberos and NTLM double-hop problem. The WinRM session cannot pass your credentials on to a second server.
Fix โ Choose one of these:
- Kerberos with delegation:
ansible_winrm_kerberos_delegation: true, with a forwardable ticket (kinit -f). become: true,become_method: runas, andbecome_user: CORP\svc_ansiblewith a password, which creates a fresh logon that has network credentials.- CredSSP transport. It works, but it sends reusable credentials, so avoid it in high-security environments.
Prevent โ Stage files from an HTTP artifact store with win_get_url instead of SMB shares, so no double hop is needed.
Q188 A playbook works locally but fails in AWX with couldn't resolve module/action 'community.mysql.mysql_db'
Intermediate
couldn't resolve module/action 'community.mysql.mysql_db'Likely causes โ AWX runs jobs inside an execution environment container, not with your laptop's collections. The EE does not include community.mysql, and the project has no collections/requirements.yml for AWX to install during project sync.
Fix โ Choose one of these:
- Add
collections/requirements.ymlto the project. AWX installs it on project sync if collection installs are allowed. - Build a custom EE:
# execution-environment.yml (ansible-builder v3)
version: 3
images:
base_image:
name: quay.io/ansible/awx-ee:latest
dependencies:
galaxy: requirements.yml
python: requirements.txt
system: bindep.txtansible-builder build -t registry.internal/acme-ee:1.4.0Prevent โ Test locally with ansible-navigator run --eei registry.internal/acme-ee:1.4.0 so local runs match AWX.
Q189 An AWX project sync fails while installing collections from Private Automation Hub, though Git checkout succeeds
Advanced
Likely causes โ AWX installs collections/requirements.yml using the Galaxy / Automation Hub credentials attached to the Organization, in the order they are listed. The hub credential is missing, out of order, or holds an expired token, so the install gets a 401 or falls back to public Galaxy, which does not have the internal collection.
Diagnose โ Open the project update job output and look for the ansible-galaxy collection install step and the server URL it called.
Fix โ Create a credential of type "Ansible Galaxy/Automation Hub API Token" with the hub URL and token, attach it to the Organization above public Galaxy, and sync again.
Prevent โ Use a service token with a known expiry and rotation reminder. Better, pre-bake internal collections into the EE.
Q190 AWX jobs stay in Pending and never start
Advanced
Pending and never startLikely causes โ
- No instance in the job's instance group has free capacity (forks ร concurrent jobs).
- The job is waiting for a dependent project or inventory update that is itself stuck.
- With container groups on Kubernetes, the job pod cannot be scheduled (resource requests, node selectors, quota) or cannot pull its EE image.
Diagnose โ
kubectl -n awx get pods | grep automation-job
kubectl -n awx describe pod <automation-job-pod> # events: Insufficient cpu, ImagePullBackOff
kubectl -n awx logs deploy/awx-task -c awx-task | tail -50In the UI, check Instance Groups for capacity and the job's "Explanation" field.
Fix โ Add capacity or adjust the job template's instance group, fix the stuck dependency job, and right-size the pod requests or fix the image pull secret.
Prevent โ Monitor capacity and pending time, and set sensible job template forks so one job cannot consume an instance's whole capacity.
Q191 An AWX inventory synced from the Git project shows the hosts, but none of the group_vars
Advanced
group_varsLikely causes โ The inventory source points at a file whose group_vars/ is in a different directory, or the hosts were added manually or by another source type. AWX imports group_vars and host_vars only when they sit next to the inventory file or directory selected in a "Sourced from a Project" source.
Diagnose โ Open the inventory source and check the "Inventory file" path. Compare it with the repository layout. Look at the variables of a group in the AWX UI.
Fix โ Point the source at inventories/prod/ (the directory) or at a file inside it, so the adjacent group_vars/ is picked up. Enable "Overwrite" and "Overwrite variables" if stale values remain, and sync again.
Prevent โ Keep the same inventory directory layout for CLI and AWX. Variables next to the playbook still load at run time, but variables next to the inventory need the right source path.
Q192 An AWX job fails with Decryption failed (no vault secrets were found that could decrypt) although a Vault credential is attached
Advanced
Decryption failed (no vault secrets were found that could decrypt) although a Vault credential is attachedLikely causes โ The project mixes vault IDs (dev, prod), and the attached credential has no Vault Identifier, or a different one, from the label in the file header. Another cause is that the credential holds a different password than the one used to encrypt.
Diagnose โ head -1 on the vault file in the repository shows the label it was encrypted with. Compare it with the credential's "Vault Identifier" field.
Fix โ Create one Vault credential per ID (Vault Identifier: prod) and attach all the ones the job needs. AWX allows several Vault credentials as long as their IDs differ.
Prevent โ Use one vault ID per environment, the same ones in the CLI and AWX, and document them in the repo README.
Q193 AWX jobs fail before starting with Error: initializing source docker://registry.internal/acme-ee:1.4.0: ... unauthorized: authentication required
Advanced
Error: initializing source docker://registry.internal/acme-ee:1.4.0: ... unauthorized: authentication requiredLikely causes โ The EE lives in a private registry, and the Execution Environment object in AWX has no Container Registry credential, or the credential has expired. On container groups, the namespace may also lack an imagePullSecret.
Fix โ Create a "Container Registry" credential and attach it to the Execution Environment in AWX. For container groups, add imagePullSecrets to the pod spec override. Set the pull policy to "Missing" for pinned tags.
Prevent โ Use immutable EE tags (1.4.0, not latest), robot or service accounts for the registry, and a test job that runs after every EE release.
Q194 ansible-navigator run site.yml fails with Permission denied (publickey), while ansible-playbook site.yml works
Advanced
ansible-navigator run site.yml fails with Permission denied (publickey), while ansible-playbook site.yml worksLikely causes โ Navigator runs the playbook inside an EE container. Your ~/.ssh keys are not visible there, and the SSH agent socket is only passed through if SSH_AUTH_SOCK is set and the agent holds the key. Custom key paths in inventory point at host paths that do not exist in the container.
Diagnose โ
ssh-add -l
ansible-navigator run site.yml -m stdout -vvv 2>&1 | grep -i identityFix โ Start the agent and add the key (eval "$(ssh-agent)"; ssh-add ~/.ssh/id_ed25519), or mount the key through the navigator settings:
ansible-navigator:
execution-environment:
volume-mounts:
- src: ~/.ssh
dest: /home/runner/.ssh
options: roUse --ee false to confirm the problem is container-specific.
Prevent โ Commit a project ansible-navigator.yml so every developer gets the same mounts and EE image.
Q195 molecule create fails with Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Intermediate
molecule create fails with Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?Likely causes โ Docker is not running, the user is not in the docker group (on Linux), or the machine only has Podman and the scenario uses the Docker driver.
Diagnose โ docker info, id -nG | grep docker, systemctl status docker.
Fix โ Start Docker and add the user to the group (sudo usermod -aG docker $USER, then log in again), or switch the scenario to Podman (driver: name: podman) with molecule-plugins[podman].
Prevent โ Document the driver in the repo and provide a dev container with Docker and Molecule preinstalled.
Q196 Molecule converge fails on service tasks with System has not been booted with systemd as init system (PID 1). Can't operate.
Advanced
System has not been booted with systemd as init system (PID 1). Can't operate.Likely causes โ The test container runs a shell or sleep as PID 1, not systemd. On cgroup v2 hosts (Ubuntu 22.04+ runners, recent Docker Desktop), systemd containers also need the right cgroup setup.
Fix โ
platforms:
- name: rocky9
image: geerlingguy/docker-rockylinux9-ansible:latest
command: /usr/sbin/init
privileged: true
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
pre_build_image: truePrevent โ Use images built for systemd testing, and keep a known-good molecule.yml template that every role copies.
Q197 Failed to find driver docker. Please ensure that the driver is correctly installed. after upgrading Molecule
Intermediate
Failed to find driver docker. Please ensure that the driver is correctly installed. after upgrading MoleculeLikely causes โ The drivers were split out of Molecule core. The old molecule-docker package is replaced by molecule-plugins[docker], and a fresh virtualenv has only the built-in default (delegated) driver.
Diagnose โ molecule drivers, pip list | grep -i molecule.
Fix โ
pip install "molecule" "molecule-plugins[docker]" dockerAlso install the community.docker collection, which the driver's create and destroy playbooks use.
Prevent โ Pin molecule, molecule-plugins, ansible-core and ansible-lint in requirements-dev.txt.
Q198 molecule verify fails with ModuleNotFoundError: No module named 'testinfra'
Intermediate
molecule verify fails with ModuleNotFoundError: No module named 'testinfra'Likely causes โ The scenario sets verifier: name: testinfra, but pytest-testinfra is not installed. Since Molecule 3, the default verifier is Ansible (verify.yml), so old scenarios often still expect testinfra.
Fix โ Run pip install pytest-testinfra, or move to the Ansible verifier:
verifier:
name: ansiblewith assertions in molecule/default/verify.yml (uri, command with changed_when: false, assert).
Prevent โ Standardise one verifier across all roles, and pin its dependencies.
Q199 Molecule passes locally but fails in GitHub Actions at Gathering Facts with /bin/sh: 1: python3: not found
Advanced
Gathering Facts with /bin/sh: 1: python3: not foundLikely causes โ The CI scenario uses a bare official image (ubuntu:24.04, debian:12) with no Python. Locally, a cached test image with Python was used.
Fix โ Use an image that has Python and systemd (pre_build_image: true), or bootstrap in prepare.yml before facts are gathered:
- hosts: all
gather_facts: false
tasks:
- ansible.builtin.raw: test -e /usr/bin/python3 || (apt-get update && apt-get install -y python3)
changed_when: falsePrevent โ Pin test images by tag or digest in molecule.yml, and run CI and local tests with the same images.
Q200 Raising ansible_winrm_operation_timeout_sec breaks every Windows host with read_timeout_sec must exceed operation_timeout_sec, and both must be non-zero
Advanced
ansible_winrm_operation_timeout_sec breaks every Windows host with read_timeout_sec must exceed operation_timeout_sec, and both must be non-zeroLikely causes โ pywinrm requires the HTTP read timeout to be greater than the WinRM operation timeout. The defaults are 30 and 20 seconds. Someone raised only the operation timeout to deal with slow tasks.
Fix โ Raise both, keeping the read timeout higher:
ansible_winrm_operation_timeout_sec: 60
ansible_winrm_read_timeout_sec: 90For long-running work (Windows Updates, large installers), do not keep inflating timeouts. Use the module's own options (for example ansible.windows.win_updates with reboot: true) or async/poll.
Prevent โ Keep WinRM tuning in group_vars/windows.yml with a comment explaining it, and test changes against one Windows host before rolling them out.