AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible 'Invalid Argument' Error: Fix Wrong Module Parameters (Guide) — Video Tutorial
Fix Ansible invalid argument errors. Resolve wrong module parameters, typos, deprecated options, and unsupported arguments with troubleshooting steps.
What You'll Learn
- Introduction
- The Demo
- Understanding the Error
- Verbose Execution
- Fixing the Code
- Successful Execution
- Conclusion
- Common Causes
- Wrong parameter name
- Module version mismatch
Full Tutorial Content
Introduction
Welcome to another episode of Ansible Pilot! I'm Luca Berton, and today we'll delve into Ansible troubleshooting, focusing on the infamous "Invalid Argument" error. This error commonly occurs when using the Ansible `file` module to create a symlink in a Linux environment. Let's explore how to reproduce, troubleshoot, and fix this issue.
The Demo
To better understand Ansible troubleshooting, let's dive into a live Playbook. We'll create a playbook (`invalidargument_error.yml`) that attempts to create a symbolic link using the `file` module. In this example, we're trying to symlink `/proc/cpuinfo` to `~/example`.
```yaml
---
- name: file module demo
hosts: all
vars:
mylink: "~/example"
mysrc: "/proc/cpuinfo"
tasks:
- name: Creating a symlink
ansible.builtin.file:
path: "{{ mylink }}"
dest: "{{ mysrc }}"
state: link
```
Executing this playbook (`ansible-playbook -i inventory invalidargument_error.yml`) results in the following error:
```bash
TASK [Creating a symlink] ******************************************************
An exception occurred during task execution.
OSError: [Errno 22] Invalid argument: b'/proc/cpuinfo'
```
Understanding the Error
The error is clear: "OSError: [Errno 22] Invalid argument." This occurs because the `file` module expects a valid source (`src`) and destination (`dest`) when creating a symlink. In our original playbook, we only provided the `path` and `dest` parameters, leading to the "Invalid argument" error.
Verbose Execution
Executing the playbook with increased verbosity (`-vvv`) provides a more detailed traceback, helping us pinpoint the issue:
```bash
ansible-playbook -i inventory invalidargument_error.yml -vvv
```
The output reveals the exact error in the `file` module, emphasizing the need for a valid source parameter.
Fixing the Code
To resolve the "Invalid Argument" error, we need to correct our playbook. The fixed playbook (`invalidargument_fix.yml`) includes the missing `src` parameter:
```yaml
---
- name: file module demo
hosts: all
vars:
mylink: "~/example"
mysrc: "/proc/cpuinfo"
tasks:
- name: Creating a symlink
ansible.builtin.file:
src: "{{ mysrc }}"
dest: "{{ mylink }}"
state: link
```
Successful Execution
Executing the fixed playbook (`ansible-playbook -i inventory invalidargument_fix.yml`) should now complete without errors:
```bash
PLAY [file module demo] ***************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [Creating a symlink] *************************************************************************
ok: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 i
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 7 min
- Category: troubleshooting
Read the full written article: Ansible 'Invalid Argument' Error: Fix Wrong Module Parameters (Guide)