Activating Ansible Auto-completion with Argcomplete Link to heading
Terminal auto-completion is a valuable tool for improving efficiency when using Ansible. By setting up argcomplete
, you can enjoy Bash auto-completion for Ansible commands. Follow these steps to enable auto-completion in your Bash terminal.
Steps to enable argcomplete
for Ansible
Link to heading
Install
argcomplete
:If
argcomplete
isn’t installed yet, you can usepip
to install it:pip install argcomplete
Activate global auto-completion:
Once
argcomplete
is installed, activate global auto-completion by running:activate-global-python-argcomplete
This command modifies your
~/.bashrc
file to register auto-completion automatically.Apply the changes:
Reload your
~/.bashrc
file to apply the changes:source ~/.bashrc
Test auto-completion for Ansible:
Test auto-completion by typing an Ansible command followed by the
Tab
key:ansible-playbook <Tab>
Optional configuration Link to heading
If you’d like to manually register auto-completion for each Ansible command, add the following lines to your ~/.bashrc
file:
eval "$(register-python-argcomplete ansible)"
eval "$(register-python-argcomplete ansible-playbook)"
eval "$(register-python-argcomplete ansible-config)"
eval "$(register-python-argcomplete ansible-doc)"
eval "$(register-python-argcomplete ansible-galaxy)"
eval "$(register-python-argcomplete ansible-inventory)"
eval "$(register-python-argcomplete ansible-pull)"
eval "$(register-python-argcomplete ansible-vault)"
Then reload ~/.bashrc
:
source ~/.bashrc
Conclusion Link to heading
By configuring argcomplete
, you enable Ansible auto-completion in Bash, greatly simplifying the use of this powerful tool.🎉