Introduction
Welcome to another episode of Ansible Pilot! I’m Luca Berton, and today we’re delving into Ansible troubleshooting, focusing on the notorious “Missing Module Parameter” error. Join me as we explore this common issue, reproduce it in a live Playbook, and learn how to resolve it effectively.
The Demo
To illustrate the troubleshooting process, let’s dive straight into a live Playbook. In this example, we have a playbook (missingparam_error.yml
) that attempts to restart the SSH daemon using the Ansible service
module. However, a critical mistake is made with a missing module parameter.
Error Code
# missingparam_error.yml
---
- name: Service module Playbook
hosts: all
become: true
tasks:
- name: Sshd restart
ansible.builtin.service:
nme: sshd
state: restarted
enabled: true
Executing this playbook (ansible-playbook -i inventory missingparam_error.yml
) results in an error due to the missing parameter:
TASK [Sshd restart] *****************************************************************
fatal: [example.com]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ nme }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: template error while templating string: unexpected 'n'. String: {{ nme }}"}
Fix Code
To rectify the issue, we need to correct our playbook. The fixed version (missingparam_fix.yml
) includes the correct module parameter:
# missingparam_fix.yml
---
- name: Service module Playbook
hosts: all
become: true
tasks:
- name: Sshd restart
ansible.builtin.service:
name: sshd
state: restarted
enabled: true
Executing the fixed playbook (ansible-playbook -i inventory missingparam_fix.yml
) should now complete without errors.
Conclusion
In this tutorial, we explored the common “Missing Module Parameter” error in Ansible. By Playbooknstrating the issue in a live demo and providing a corrected playbook, we’ve learned how to troubleshoot and fix this type of error effectively.
I hope this guide helps you navigate and resolve similar issues in your Ansible automation journey. If you found this information valuable, consider subscribing for more Ansible insights.
Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.Academy
Learn the Ansible automation technology with some real-life examples in my Udemy 300+ Lessons Video Course.
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate