I am currently writing several playbooks for server configuration, but I constantly find myself switching back and forth between my terminal and a web browser to check the Ansible documentation. Is there a built-in command-line tool that allows me to view module details, required parameters, and usage examples without leaving the CLI? I specifically need to see the available options for the apt and copy modules. Does Ansible provide a way to output this information in a concise format so I can verify my syntax on the fly?
3 answers
The primary tool for this is the ansible-doc command. It acts like a "man page" specifically for Ansible modules. To see the full documentation for a specific module, you simply run ansible-doc <module_name> (e.g., ansible-doc apt). This will provide a comprehensive list of all parameters, their default values, and—most importantly—example snippets at the bottom of the output that you can copy and paste into your playbooks. If you only want a quick, condensed list of the available options without the long descriptions, you can use the -s (snippet) flag: ansible-doc -s copy. This is a lifesaver for cloud technology engineers who want to stay focused within their terminal environment.
Are you looking for documentation on built-in modules only, or are you also trying to find details for modules included in external collections you've installed?
I find that piping the output to grep helps a lot when I'm looking for a specific keyword inside a complex module's documentation. For example: ansible-doc yum | grep -A 5 "state".
I agree with Sarah. Using grep or just using the / search key while inside the ansible-doc pager (which usually uses less) makes finding specific parameter requirements much faster than scrolling through pages of text
That’s an important distinction, Simon. For modules in collections, you have to use the fully qualified collection name (FQCN). For example, if you're using the community AWS collection, you would run ansible-doc community.aws.ec2_instance. If ansible-doc can't find it, make sure your ANSIBLE_COLLECTIONS_PATH is configured correctly. Another pro tip: use ansible-doc -l to see a massive list of every single module currently available on your system. It's a great way to discover new tools for your automation stack