~iany/blog

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.

--langdef=ansible
--langmap=ansible:.yml.yaml
--regex-ansible=/^[ \t]*-[ \t]*name:[ \t]*(.+)/\1/k,tasks/
--languages=ansible,ruby,python

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',
  \ }

Keystroke Sequence Shortcuts in Mac OS X

It is a headache to find an available keyboard shortcuts in Mac OS X. I used Option + Letter and Shift + Option + Letter before, since they are preserved for inputting special characters. It has some problems:

  • Emacs and terminal require a modifier for Meta. I choosed Command. It means if I want to use application shortcut with Command in these applications, such as Command+Q to quit the application, I have to use the right one.
  • I always forget the shortcuts. Although I have listed them in a sheet, it is a pain to keep it synchronized with the shortcuts defined every where.

I switched to a new solution using keystroke sequence shortcuts recently. All my global shortcuts start with Command+M (⌘M). A menu is displayed when I typed prefix. If I forget the shortcut, I just need to glance through the menu.