Provideabashcompletiononhostname,modulenameandoptionsforansible.
ImportantAsofAnsible2.9,youcanaddshellcompletionoftheAnsiblecommandlineutilitiesbyinstallinganoptionaldependencycalledargcomplete.argcompletesupportsbash,andhaslimitedsupportforzshandtcsh.
Thedifferencewiththeofficialauto-completionisansible-completionsupportcompletionofthehosts,basedontheinventoryfile,andmodules.Theofficialauto-completionishowevermuchmoreup-to-datewithalltheargumentsnames.
InstallationGettheansible-completion.bashfile.
Copy/movetheansible-completion.bashinyourbash_completion.dfolder(/etc/bash_completion.d,/usr/local/etc/bash_completion.dor~/bash_completion.d).
Orcopy/moveitwhereyouwantandthenloadtheansible-completion.bashfileinyour~/.bashrcor~/.profilelikethat:source~/ansible-completion.bash
Reloadyourshellwithsomethinglikesource~/.bashrcorsource~/.profile
NoteforOSXClonetherepo,installbashanauto-completion2withhomebew:brewinstallbashbash-completion2
Changeyourterminalbashtoahomebrewonebysettingthecommandoptionto/usr/local/bin/bash
Addthefollowingcodetoyour~/.profile:
if[-f$(brew--prefix)/share/bash-completion/bash_completion];then.$(brew--prefix)/share/bash-completion/bash_completionfiCreateasymboliklinkforansible-completion.bash:
ln-vs~/soft/ansible-completion/ansible-completion.bash/usr/local/share/bash-completion/completions/ansibleGoodtoknowIfthe--module-path(-M)or--inventory-file(-i)isonthecommandline,thecompletionwilluseit.
Forthecompletiononmodulename,thecompletionscriptbuildacacheofmodulesnames.
YoucansetthecachetimeoutwiththeenvironementvariableANSIBLE_COMPLETION_CACHE_TIMEOUT,thedefaultvalueis120seconds.
Contributorsogarciapheanex(ansible-*completions)DenKorenhryamzikmrqwer88wolfgangkarall
评论