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
argcompleteisn’t installed yet, you can usepipto install it:pip install argcompleteActivate global auto-completion:
Once
argcompleteis installed, activate global auto-completion by running:activate-global-python-argcompleteThis command modifies your
~/.bashrcfile to register auto-completion automatically.Apply the changes:
Reload your
~/.bashrcfile to apply the changes:source ~/.bashrcTest auto-completion for Ansible:
Test auto-completion by typing an Ansible command followed by the
Tabkey: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.🎉