Where Are Ansible Modules Stored? Location & Path Guide
By Luca Berton · Published 2024-01-01 · Category: installation
Find where Ansible modules are stored. Locate built-in modules, collection modules, custom modules, and configure module search paths with examples.
Ansible logs are crucial for debugging, auditing, and monitoring your automation workflows. By default, Ansible does not log to a file unless explicitly configured. This article explains where Ansible logs are stored, how to enable logging, and best practices for managing log files.
Where Are Ansible Logs Stored?
Default Behavior
By default, Ansible logs output to the terminal (stdout) during playbook execution. To capture logs in a file, you must configure the logging settings in theansible.cfg file.
Enabling Logging in Ansible
To enable logging, follow these steps:
- Open or create the
ansible.cfgfile in your project directory or system-wide configuration path (e.g.,/etc/ansible/ansible.cfg). - Add or modify the following lines under the
[defaults]section:
[defaults]
log_path = /var/log/ansible/ansible.log
This configuration stores logs in /var/log/ansible/ansible.log.
- Ensure the directory exists and has appropriate permissions:
sudo mkdir -p /var/log/ansible
sudo chmod -R 755 /var/log/ansible
- Verify the configuration by running a playbook:
ansible-playbook playbook.yml
Logs will be written to the specified file.
See also: Project Policy Validation with OPA and ansible-policy
Common Log File Locations
- Project-Specific Logs:
ansible.cfg, logs will be stored in the project directory:
./ansible.log
- System-Wide Logs:
/var/log/ansible/ansible.log
- Custom Paths:
log_path setting.
Using Environment Variables for Logging
Set the log file path dynamically using the ANSIBLE_LOG_PATH environment variable:
export ANSIBLE_LOG_PATH=/custom/path/ansible.logThis overrides the log_path setting in the configuration file for the current session.
See also: What Are Ansible Playbooks? Definition, Structure, and Examples (2026 Guide)
Log Levels and Verbosity
To capture detailed information in logs, use the -v (verbose) option during playbook execution:
-v: Basic verbosity.-vv: More detailed logs.-vvv: Debug-level logs.
ansible-playbook playbook.yml -vvvThe increased verbosity helps in diagnosing complex issues.
Managing Log File Size
Large log files can become difficult to manage. Use log rotation to limit file size and maintain historical data:
- Install and configure
logrotate:
sudo apt install logrotate
- Add a custom configuration for Ansible logs:
/var/log/ansible/ansible.log {
rotate 7
daily
compress
missingok
notifempty
}
This configuration rotates the log file daily, keeps seven days of logs, and compresses older logs.
See also: Ansible Variables: Complete Guide to vars, facts & Precedence
Best Practices for Ansible Logging
- Centralize Logs:
- Secure Logs:
- Use Separate Logs for Projects:
- Enable Debug Logging for Issues:
- Rotate Logs Regularly:
Conclusion
Ansible logs are not stored by default but can be enabled and customized through the ansible.cfg file or environment variables. By setting up logging properly and following best practices, you can efficiently manage and analyze logs to optimize your automation workflows.
Learn More About Ansible Logging
Find Module Locations
# Show configured module paths
ansible-config dump | grep DEFAULT_MODULE_PATH
# Find a specific module's file
ansible-doc -t module ansible.builtin.copy --json | python3 -c "import sys,json; print(json.load(sys.stdin)['ansible.builtin.copy']['doc']['filename'])"
# Or simply
python3 -c "import ansible.modules; print(ansible.modules.__path__)"Module Storage Locations
| Type | Path |
|---|---|
| Built-in | |
| Collections (user) | ~/.ansible/collections/ansible_collections/ |
| Collections (system) | /usr/share/ansible/collections/ansible_collections/ |
| Custom (project) | ./library/ (relative to playbook) |
| Custom (global) | Path in ansible.cfg library setting |
Check Built-in Module Location
# Find ansible installation
python3 -c "import ansible; print(ansible.__file__)"
# Example: /usr/lib/python3/dist-packages/ansible/__init__.py
# Built-in modules are at:
# /usr/lib/python3/dist-packages/ansible/modules/Collection Module Locations
# List all collections and their paths
ansible-galaxy collection list
# Find specific collection
ansible-galaxy collection list community.general
# Path: /home/user/.ansible/collections/ansible_collections/community/general
# Modules inside collection:
ls ~/.ansible/collections/ansible_collections/community/general/plugins/modules/Add Custom Module Path
Project-level (./library/)
my-project/
library/
my_custom_module.py # Auto-discovered
playbooks/
site.ymlansible.cfg
[defaults]
library = ./library:/opt/ansible/modulesEnvironment variable
export ANSIBLE_LIBRARY=./library:/opt/ansible/modulesList Available Modules
# All modules
ansible-doc -l
# Filter by keyword
ansible-doc -l | grep docker
# Module documentation
ansible-doc ansible.builtin.copy
# Module parameters (short form)
ansible-doc -s ansible.builtin.copyBuilt-in vs Collection Modules
| Category | Location |
|---|---|
ansible.builtin. | Bundled with Ansible core |
community.general. | Installed via ansible-galaxy |
amazon.aws.* | Installed via ansible-galaxy |
| Custom | ./library/ or configured path |
FAQ
Can I edit built-in modules?
Technically yes, but it's overwritten on upgrade. Create a custom module in ./library/ instead — it takes precedence over built-in modules with the same name.
How do I check which module version I have?
ansible-doc ansible.builtin.copy | head -5
ansible-galaxy collection list community.generalWhere are Windows modules?
In the ansible.windows collection:
ls ~/.ansible/collections/ansible_collections/ansible/windows/plugins/modules/How do I write a custom module?
Create a Python file in ./library/:
#!/usr/bin/python
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(argument_spec=dict(name=dict(required=True)))
module.exit_json(changed=False, msg="Hello " + module.params['name'])
if __name__ == '__main__':
main()Find Module Locations
# Show all module paths
ansible-config dump | grep MODULE
# Show specific module location
ansible-doc -t module ansible.builtin.copy --json | python3 -c "import sys,json; print(json.load(sys.stdin)['ansible.builtin.copy']['doc']['filename'])"
# Quick way
python3 -c "import ansible; print(ansible.__file__)"Default Locations
Built-in Modules (ansible.builtin)
# Inside the ansible-core Python package
<python-site-packages>/ansible/modules/
# Common paths:
/usr/lib/python3/dist-packages/ansible/modules/
/usr/local/lib/python3.11/dist-packages/ansible/modules/
~/.local/lib/python3.11/site-packages/ansible/modules/
# In virtual environments:
/path/to/venv/lib/python3.11/site-packages/ansible/modules/Collection Modules
# Default collection path
~/.ansible/collections/ansible_collections/<namespace>/<collection>/plugins/modules/
# Example:
~/.ansible/collections/ansible_collections/community/general/plugins/modules/
~/.ansible/collections/ansible_collections/amazon/aws/plugins/modules/System-Wide Collections
/usr/share/ansible/collections/ansible_collections/Custom Module Paths
Project-Level
project/
├── library/ ← Ansible looks here automatically
│ └── my_module.py
├── ansible.cfg
└── playbook.ymlIn ansible.cfg
[defaults]
library = ./library:/opt/ansible/modulesEnvironment Variable
export ANSIBLE_LIBRARY=/opt/custom-modules:$ANSIBLE_LIBRARYIn Roles
roles/webserver/
└── library/ ← Available when role is used
└── my_module.pyList All Available Modules
# All modules
ansible-doc -l
# Modules in a collection
ansible-doc -l -t module community.general
# Search for modules
ansible-doc -l | grep docker
# Module documentation
ansible-doc ansible.builtin.copyCollection Paths
# Show collection search paths
ansible-galaxy collection list
# Default paths (in order):
# 1. ./collections/
# 2. ~/.ansible/collections/
# 3. /usr/share/ansible/collections/# ansible.cfg
[defaults]
collections_path = ./collections:~/.ansible/collectionsModule Resolution Order
library/in playbook directorylibrary/in role being executed- Paths from
ANSIBLE_LIBRARYoransible.cfg library= - Collection modules (by FQCN)
- Built-in
ansible.builtinmodules
Create a Custom Module
# library/my_module.py
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['present', 'absent']),
)
)
name = module.params['name']
module.exit_json(changed=True, msg=f"Processed {name}")
if __name__ == '__main__':
main()# Use it
- my_module:
name: test
state: presentFAQ
How do I find which collection provides a module?
ansible-doc <module-name>
# Shows the collection and file path at the topCan I override a built-in module?
Yes — place a module with the same name in library/. Local modules take precedence over built-in ones.
Modules not found after pip install?
Ensure you're using the same Python/venv. Check: which ansible and ansible --version to verify paths.
Related Articles
Category: installation