Does anybody know if there is a sublime text plugin that does syntax highlighting for Ansible playbooks? I’m using the YAML one, but it gets confused by braces such as with the new {{ var }} variable substitution and the old ${var} substitution syntaxes.
It all gets confused by things like commas in unquoted text strings, e.g.:
- name: Install, configure and start nginx
And the ampersand also trips it up:
hosts: webservers:&$hosts
Lorin
did you ever find one?
I was looking for the same. I’m also building a bunch of snippet shortcuts for building module skeletons to be tab-complete filled in.
kesten
I’m not aware of one existing FWIW.
Might be something that needs to be developed.
I would definitely be interested and we could link it on the main website.
Excerpts from Michael DeHaan's message of 2013-10-05 16:06:10 -0400:
I'm not aware of one existing FWIW.
Might be something that needs to be developed.
I would definitely be interested and we could link it on the main website.
Vim's syntax highlighting for YAML has a few problems too. It'd be nice
to fix those in syntax/yaml.vim upstream (as most of them are
technically valid YAML, no ansible-specific).
It could even be nice to have an ansible-specific syntax file that
highlighted the jinja2 business the way the jinja2 syntax file does.
Either one, we'll need someone who knows them some Vim regexes real
good. If anyone fits that description, I can supply a list of
misbehaviors I've noticed in Vim's YAML syntax file.
Not a huge deal either way, though.
Hi Kesten,
Regarding the snippets, not sure if you were aware of this (posted by bleader almost a year ago): https://groups.google.com/forum/#!searchin/ansible-project/bleader/ansible-project/FngiYrCtmUk/SflXVjkHjkkJ. It automatically builds the snippets based on the embedded documentation within a module.
I had made a few updates to my local copy of that to keep it working, and was going to submit a pull request but it looks like someone beat me to it about 3 months ago It’s a really useful tool for those who edit their Ansible playbooks with vim!
matt
Morgan,
I would be interested in seeing a list of .yaml syntax problems you’ve noticed, in case i’m able to get to it sooner than later.
Matt,I wasn’t aware of the vim snippet generator. I wrote something similar for generating sublime-snippet’s from the embedded docs in the github repo. It works, fairly well. A few corner cases to smooth. I will make it available next weekend.
This won’t fix the yaml syntax highlighting. It just enables:
type the first three letters of an ansible command
hit tab
sublime completes it with a skeleton of the module with all the options.
you can then edit the snippet to remove the options you don’t typically use.
This is especially useful for newbs to avoid having to flip back to the documentation every few seconds to see what options you need to fill for a command.
Lots more functionality could be added (like displaying all possible values for an option) but it’s a functional start.
Sublime is python-based, so it integrates pretty easily with ansibleizing.
k
I’d be interested as well.
Slightly off topic, but anyone have any ideas on how to keep yaml syntax highlighting turned on for host/group_vars files? host_vars/hostname doesn’t have the yml extension, so ST doesn’t know to use the correct highlighting. Or can I add the yml extension to those files? Hmm…
david,
you will have to be ok with all files without an extension taking on yaml syntax highlighting
View -> Syntax -> Open all with current extension as... ->[your syntax choice]
http://stackoverflow.com/questions/7574502/set-default-syntax-to-different-filetype-in-sublime-text-2
Hi Michael,
I have started writing a syntax definition file: https://github.com/clifford-github/sublime-ansible
Maybe this would be a starting point?
Regards,
Clifford
cool, i’ll try it out today.
I have a snippet component.
It reads the usage statements from the ansible code files.
Type the first 3 letters, hit tab and you get the full list of options which you can then tab to and edit.
To do this, i build
library[module_group_name][module]
and you can access things like this:
library[‘files’][‘assemble’][‘options’][‘src’][‘description’]
Might be useful going forward.
Did you want to put your stuff in a common repo somewhere or keep em separate for now?
kesten
what do you mean with ‘common repo’?
BTW: I wrote the syntax file for task files only. I’ll be adding inventory and var files next.
Clifford
well, i could create my own repo so people could download stuff, or you could accept pull requests from me so others would have a single download point for all sublime-ansible stuff.
One thing i was wondering was about extensions. There is a jinja2 highlighter available for sublime (not particularly great) but you are then forced to use the .j2 extension for all items in the templates folder. This makes use of with_fileglob tricky for example, as you have to strip off the .j2 when moving it to a host. (doable with jinja filters, but trickier than not doing it).
I don’t know if it would be possible to recognize everything in templates as a jinja2 rather than by the usual recognize by file extension.
k
looking forward to accept your pull request. we can discuss further features on github.
Clifford