diff options
Diffstat (limited to 'Completion/Unix/Command/_ansible')
-rw-r--r-- | Completion/Unix/Command/_ansible | 208 |
1 files changed, 144 insertions, 64 deletions
diff --git a/Completion/Unix/Command/_ansible b/Completion/Unix/Command/_ansible index f1e13a813..2d976b0a0 100644 --- a/Completion/Unix/Command/_ansible +++ b/Completion/Unix/Command/_ansible @@ -1,7 +1,7 @@ -#compdef ansible ansible-config ansible-console ansible-doc ansible-galaxy ansible-inventory ansible-playbook ansible-pull ansible-vault -value-,ANSIBLE_STDOUT_CALLBACK,-default- +#compdef ansible ansible-config ansible-console ansible-doc ansible-galaxy ansible-inventory ansible-playbook ansible-pull ansible-vault -value-,ANSIBLE_STDOUT_CALLBACK,-default- -value-,ANSIBLE_INVENTORY_ENABLED,-default- -local curcontext="$curcontext" plug plugvar ign ret=1 -local -a args state line +local curcontext="$curcontext" plug plugvar subcmd ign ret=1 +local -a args state line expl gactions local -A opt_args case $service in @@ -9,6 +9,10 @@ case $service in plug=callback state=plugins ;; + *,ANSIBLE_INVENTORY_ENABLED,*) + plug=inventory + state=plugins + ;; ansible|ansible-console|ansible-doc|ansible-playbook) args=( \*{-M+,--module-path=}'[specify path to modules]:module path:_dir_list' @@ -18,6 +22,8 @@ case $service in args+=( '(-K --ask-become-pass)'{-K,--ask-become-pass}'[ask for privilege escalation password]' '(-k --ask-pass)'{-k,--ask-pass}'[ask for connection password]' + '--list-hosts[output list of matching hosts]' + '(-l --limit)'{-l+,--limit=}'[further limit hosts to an additional pattern]:host subset:->hosts' '(-T --timeout)'{-T+,--timeout=}'[override the connection timeout]:timeout (seconds) [10]' '(-c --connection)'{-c+,--connection=}'[specify connection type]:connection type [smart]:->connect-types' '(-u --user)'{-u+,--user=}'[specify remote user for connection]:remote user:_users' @@ -40,31 +46,17 @@ case $service in '!(-R --su-user -U --sudo-user)'{-R,-U,--su-user,--sudo-user}':user [root]:_users' ) ;| - ansible|ansible-console|ansible-inventory|ansible-playbook|ansible-pull|ansible-vault) - args+=( - '--ask-vault-pass[ask for vault password]' - '--vault-id=[specify vault identity to use]:vault identity' - '--vault-password-file=[specify vault password file]:vault password file:_files' - ) - ;| ansible|ansible-console|ansible-inventory|ansible-playbook|ansible-pull) args+=( + --ask-vault-pass{,word}'[ask for vault password]' + '(-e --extra-vars)'{-e+,--extra-vars=}'[set additional variables]:key=value or YAML/JSON' + '--vault-id=[specify vault identity to use]:vault identity' + --vault-pass{,word}-file='[specify vault password file]:vault password file:_files' \*{-i+,--inventory=}'[specify inventory host file or host list]: : _alternative "files\:inventory file\:_files" "hosts\:host\: _sequence _hosts"' '!(-i --inventory)--inventory-file=:inventory file:_files' ) ;| - ansible|ansible-console|ansible-playbook|ansible-pull) - args+=( - '--list-hosts[output list of matching hosts]' - '(-l --limit)'{-l+,--limit=}'[further limit hosts to an additional pattern]:host subset:->hosts' - ) - ;| - ansible|ansible-playbook|ansible-pull) - args+=( - '(-e --extra-vars)'{-e+,--extra-vars=}'[set additional variables]:key=value or YAML/JSON' - ) - ;| ansible|ansible-console|ansible-inventory) args+=( '--playbook-dir=[specify substitute playbook directory]:directory:_directories' @@ -72,15 +64,20 @@ case $service in ;| ansible-playbook|ansible-pull) args+=( - '(-t --tags)'{-t,--tags}'[only run plays and tasks tagged with these values]' + '(-t --tags)'{-t,--tags}'[only run plays and tasks tagged with these values]:tag:->tags' "--skip-tags[only run plays and tasks whose tags don't match]" ) ;| + ansible|ansible-console) + args+=( + '--task-timeout[set the task timeout limit]:timeout (seconds)' + ) + ;| ansible) args+=( '(-a --args)'{-a+,--args=}'[specify command or module arguments]:arguments:->args' '(-B --background)'{-B+,--background=}'[run asynchronously, failing after specified time]:fail timeout (seconds)' - '(-m --module-name)'{-m+,--module-name=}'[specify module]:module:->plugins' + '(-m --module-name)'{-m+,--module-name=}'[specify action to execute]: :->plugins' '(-o --one-line)'{-o,--one-line}'[condense output]' '(-P --poll)'{-P+,--poll=}'[specify the poll interval if using -B]:interval (seconds) [15]' '(-t --tree)'{-t+,--tree=}'[specify directory for log output]:directory:_directories' @@ -106,11 +103,15 @@ case $service in ;; ansible-doc) args+=( - '!(-l --list -F --list_files -s --snippet)'{-j,--json} # "internal testing only" - '(-l --list -F --list_files -s --snippet)'{-l,--list}'[list available plugins]' - '(-l --list -F --list_files -s --snippet)'{-F,--list_files}'[show plugin names and their source files without summaries]' - '(-l --list -F --list_files -s --snippet)'{-s,--snippet}'[show playbook snippet for specified plugins]' - '(-t --type)'{-t+,--type=}'[choose plugin type]:plugin type [module]:(become cache callback cliconf connection httpapi inventory lookup shell module strategy vars)' + '!--metadata-dump' # "internal testing only" + '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-j,--json}'[change output to json format]' + '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-l,--list}'[list available plugins]' + '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-F,--list_files}'[show plugin names and their source files without summaries]' + '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-s,--snippet}'[show playbook snippet for specified plugins]' + '(-l --list -F --list_files -s --snippet -e --entry-point)--metadata-dump[dump json metadata for all plugins]' + '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-e+,--entry-point=}'[select the entry point for roles]:entry point' + '(-t --type)'{-t+,--type=}'[choose plugin type]:plugin type [module]:(become cache callback cliconf connection httpapi inventory lookup netconf shell vars module strategy role keyword)' + '(-r --roles-path)'{-r+,--roles-path=}'[specify directory containing roles]:directory:_directories' '*:plugin:->plugins' ) ;; @@ -124,15 +125,16 @@ case $service in '(-y --yaml --vars --graph)--toml[use TOML format instead of JSON]' '(-y --yaml)--vars[add variables to the graph display]' '(-y --yaml --toml --vars --graph)'{-y,--yaml}'[use YAML format instead of JSON]' + ':host or group:->hosts' ) ;; ansible-galaxy) - args+=( -A "-*" $args + args=( -A "-*" $args '--list[list integrations]' '(-c --ignore-certs)'{-c,--ignore-certs}'[ignore SSL certificate validation errors]' '(-s --server)'{-s+,--server=}'[specify API server destination]:server destination' '--remove=[remove integration]:integration id' - '1:action:(delete import info init install list login remove search setup)' + '::type:(collection role)' '*::args:->galaxy' ) ;; @@ -154,7 +156,7 @@ case $service in '(-d --directory)'{-d+,--directory=}'[specify directory to checkout repository to]:directory:_directories' '--full[do a full instead of a shallow clone]' '(-m --module-name)'{-m+,--module-name=}'[specify repository module used for checking out repository]:module:(git subversion hg bzr)' - '--accept-host-key[adds the hostkey for the repo url if not already added]' + '--accept-host-key[add the hostkey for the repo url if not already added]' '--purge[purge checkout after playbook run]' '(-f --force)'{-f,--force}'[run the playbook even if the repository could not be updated]' '(-C --checkout)'{-C,--checkout}'[specify branch/tag/commit to checkout]:branch/tag/commit' @@ -168,9 +170,7 @@ case $service in ;; ansible-vault) args=( -A "-*" $args - '::action:(create decrypt edit encrypt encrypt_string rekey view)' - '--new-vault-id=[specify new vault identity to use for rekey]:vault id' - '--new-vault-password-file=[specify new vault password file to use for rekey]:file:_files' + '::action:compadd -M "r:|_=* r:|=*" - create decrypt edit encrypt encrypt_string rekey view' '*::args:->vault' ) ;; @@ -225,34 +225,82 @@ case $state in if zstyle -T ":completion:${curcontext}:plugins" verbose; then (( ${(P)#plugvar} )) || set -A ${plugvar} \ ${${(f)"$(_call_program plugins ansible-doc -t $plug -l)"}/ ##/:} - _describe -t plugins "${plug} plugin" $plugvar && ret=0 + _describe -t plugins "${plug} plugin" $plugvar -M 'r:|.=* r:|=*' && ret=0 else (( ${(P)#plugvar} )) || set -A ${plugvar} \ ${${(f)"$(_call_program plugins ansible-doc -t $plug -F)"}%% *} - _wanted plugins expl "${plug} plugin" compadd -a $plugvar && ret=0 + _wanted plugins expl "${plug} plugin" compadd -M 'r:|.=* r:|=*' -a $plugvar && ret=0 fi ;; + tags) + # The recursive glob here is questionable and perhaps there should be a style. + _sequence _wanted tags expl tag compadd - \ + ${(s.,.)${(j.,.)${(M)${(f)"$(cat **/*.yml)"}:# #tags:*}#*: }} && ret=0 + ;; galaxy) ign='' - curcontext="${curcontext%:*}-${line[1]}:" - (( $#words > 2 )) && ign='!' + gactions=( delete import info init install list remove search setup ) + case ${(j.:.)line[1,3]} in + (role|collection):*:*) + subcmd="${line[1]}-${line[2]}" + ;; + collection:*) + gactions=( init build publish install ) + subcmd=collection + ;; + role:*) subcmd=role ;; + *:*) subcmd="role-${line[1]}" ;& + [^:]#) + words=( role "$words[@]" ) + (( CURRENT++ )) + ;; + esac + curcontext="${curcontext%:*}-${subcmd}:" + (( $#words > 3 )) && ign='!' args=( "${ign}(-)"{-h,--help}'[display usage information]' - '(-c --ignore-certs)'{-c,--ignore-certs}'[ignore SSL certificate validation errors]' - '(-s --server)'{-s+,--server=}'[specify API server destination]:server:_hosts' - {-v,--verbose}'[verbose mode]' + '1: :{ _wanted actions expl action compadd -a gactions }' ) - case $line[1] in - info|search|list|remove|install) + case $subcmd in + *-*) + args+=( + '(-c --ignore-certs)'{-c,--ignore-certs}'[ignore SSL certificate validation errors]' + '(-s --server)'{-s+,--server=}'[specify API server destination]:server:_hosts' + --{token,api-key}='[specify ansible galaxy API key]:api key' + \*{-v,--verbose}'[verbose mode]' + ) + ;| + role-setup) # order important here, source comes before github args + args+=( ': :_guard "^-*" "source"' '*:secret' ) + ;| + role-(delete|import|setup)) + args+=( ': :_guard "^-*" "github username"' ':github repository' ) + ;| + role-(info|init|install|list|remove)) + args+=( '*: :_guard "^-*" "role name"' ) + ;| + role-(info|search|list|remove|install)) args+=( '(-p --roles-path)'{-p,--roles-path}'[specify location of roles]:path:_directories' ) ;| - info|init) + role-(info|init)) args+=( "--offline[don't query the galaxy API]" ) ;| - init|install) - args+=( '(-f --force)'{-f,--force}'[force overwriting an existing role]' ) + *-(init|build|install)) + args+=( '(-f --force)'{-f,--force}'[force overwriting an existing role or collection]' ) ;| - search) + *-install) + args+=( + '(-i --ignore-errors)'{-i,--ignore-errors}'[ignore errors and continue with the next specified role/collection]' + '(-n --no-deps)'{-n,--no-deps}"[don’t download roles/collections listed as dependencies]" + "--force-with-deps[force overwriting an existing role/collection and it's dependencies]" + ) + ;| + *-init) + args+=( + '--init-path=[specify path in which the skeleton will be created]:path:_directories' + ) + ;| + role-search) args+=( '--author=[specify GitHub username]:username' '--galaxy-tags=[specify list of galaxy tags to filter by]:galaxy tags' @@ -260,29 +308,25 @@ case $state in '*: :_guard "^-*" "search term"' ) ;; - setup) + role-setup) args+=( '--list[list integrations]' '--remove=[remove integration]:integration id' ) ;; - init) + role-init) args+=( - '--init-path=[specify path in which the skeleton role will be created]:path:_directories' - '--role-skeleton=[specify path to a role skeleton that the new role should be based upon]' + '--role-skeleton=[specify path to a role skeleton that the new role should be based upon]:path:_files' '--type=[initialize using an alternate role type]:role type:(container apb network)' ) ;; - install) + role-install) args+=( - "--force-with-deps[force overwriting an existing role and it's dependencies]" - '(-n --no-deps)'{-n,--no-deps}"[don’t download roles listed as dependencies]" - '(-i --ignore-errors)'{-i,--ignore-errors}'[ignore errors and continue with the next specified role]' '(-g --keep-scm-meta)'{-g,--keep-scm-meta}'[use tar instead of the scm archive option when packaging the role]' '(-r --role-file)'{-r+,--role-file=}'[specify file containing a list of roles to be imported]:file:_files' ) ;; - import) + role-import) args+=( '--status[check the status of the most recent import request for given github_user/github_repo]' "--no-wait[don’t wait for import results]" @@ -290,34 +334,70 @@ case $state in '--role-name=[specify name the role should have]:role' ) ;; - login) + collection-build) + args+=( + '--output-path=[specify path in which the collection is built to]:path [.]:_directories' + '*:collection directory to build:_directories' + ) + ;; + collection-init) args+=( - '--github-token=[identify with github token rather than username and password]' + '--collection-skeleton=[specify path to a collection skeleton that the new role should be based upon]:path:_files' + ': :_guard "^-*" "collection name"' ) ;; + collection-publish) + args+=( + "--no-wait[don't wait for import validation results]" + '--import-timeout=[specify time to wait for import process]:time' + ':collection tarball:_files' + ) + ;; + collection-install) + args+=( + '(-p --collections-path)'{-p+,--collections-path=}'[specify directory containing collections]:_directories' + '(-r --requirements-file *)'{-r+,--requirements-file=}'[specify file containing a list of collections to install]:file:_files' + '--pre[include pre-release versions]' + '*:collection name:_files' + ) + ;; esac - _arguments -s -S $args && ret=0 + _arguments -s -S : $args && ret=0 ;; vault) + ign='' curcontext="${curcontext%:*}-${line[1]}:" - args=() + (( $#words > 2 )) && ign='!' + args=( + "${ign}(-)"{-h,--help}'[display usage information]' + --ask-vault-pass{,word}'[ask for vault password]' + '--vault-id=[specify vault identity to use]:vault identity' + --vault-pass{,word}-file='[specify vault password file]:vault password file:_files' + \*{-v,--verbose}'[verbose mode]' + ) case $line[1] in - encrypt*|edit|rekey) + create|(de|en)crypt*|edit|rekey) args+=( '--encrypt-vault-id=[specify vault id to use to encrypt (required if more than one vault-id is provided)]:vault id' ) ;| - (de|en)crypt*) args=( '--output=[specify output file name]:file:_files' ) ;| + (de|en)crypt*) args+=( '--output=[specify output file name]:file:_files' ) ;| encrypt_string) args+=( '(-p --prompt)'{-p,--prompt}'[prompt for the string to encrypt]' + "--show-input[don't hide input when prompted for the string to encrypt]" '(-n --name)'{-n+,--name=}'[specify the variable name]:variable' '--stdin-name=[specify the variable name for stdin]:variable' ) ;| create|edit|rekey|view) args+=( ':file:_files' ) ;| - (en|de)crypt) args+=( '::file:_files' ) - ;; + decrypt|rekey) + args+=( + '--new-vault-id=[specify new vault identity to use]:vault identity' + '--new-vault-password-file=[specify new vault password file]:vault password file:_files' + ) + ;| + (en|de)crypt) args+=( '::file:_files' ) ;; esac _arguments -s -S $args && ret=0 ;; |