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

  1. Install argcomplete:

    If argcomplete isn’t installed yet, you can use pip to install it:

    pip install argcomplete
    
  2. 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.

  3. Apply the changes:

    Reload your ~/.bashrc file to apply the changes:

    source ~/.bashrc
    
  4. 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.🎉