Ctags for Ansible

Ansible uses YAML to define tasks, playbooks and handlers. If the files follow some conventions, it is easy to index them using Exuberant Ctags.

For example, following ctags options will index all the lines starting with - name: in .yml and .yaml files. Save it as .ctags in the playbook or role top directory.

--regex-ansible=/^[ \t]*-[ \t]*name:[ \t]*(.+)/\1/k,tasks/

It is assumed that playbook and task files use extention .yml or .yaml. And name field just follows -.

- name: name must be the first field just following the dash
  hosts: all
  roles: [ site ]

Now generate the tags

ctags -R .

And try it in vim

:tselect /keyword

To make it works with ctrlp CtrlPBufTag, add following config in vimrc

let g:ctrlp_buftag_types = {
  \ 'yaml'     : '--languages=ansible --ansible-types=k',
  \ }
comments powered by Disqus