How to use Ansible layer in Spacemacs?

I am trying to understand how to write Ansible roles and test them using this layer. I added ansible to dotspacemacs-configuration-layers, restarted Spacemacs and checked Messages to see what is loaded.

Loading /home/anatoli/.emacs.d/layers/+tools/ansible/packages.el (source)...done
Loading /home/anatoli/.emacs.d/layers/+tools/ansible/layers.el (source)...
Loading /home/anatoli/.emacs.d/layers/+lang/yaml/packages.el (source)...done
Loading /home/anatoli/.emacs.d/layers/+tools/ansible/layers.el (source)...done
Loading /home/anatoli/.emacs.d/layers/+tools/ansible/funcs.el (source)...done
Loading /home/anatoli/.emacs.d/layers/+tools/ansible/config.el (source)...done

I still don't see anything. SPC m h a from documentation doesn't work - resulting in SPC m is undefined. Spacemacs shows /YAML\ at the bottom near the filename. I don't see that Spacemacs detected YAML file as an Ansible playbook - I don't get any hints or errors displayed on the screen. Perhaps I need to change mode from YAML to Ansible somehow. If so - how do I do this?

1 Answer 1


For the Ansible layer to take action, your buffer filename must match one of main.yml, site.yml, roles/.+\.yml, group_vars/.+, etc. See the regex at the bottom of ansible/config.el (v0.200.13) for exact patterns.

EDIT: I added some additional paths to the regex above in PR #12726, which will go into Spacemacs v0.300.x.

In Emacs, you can manually enable ansible-doc-mode for the current buffer with M-x ansible-doc-mode RET. You'd probably also want to enable the company back-end with M-: (add-to-list 'company-backends 'company-ansible) RET. Then use M-x ansible RET to toggle the Ansible minor mode, which provides syntax highlighting, completion, vault functions, etc.

Unfortunately, it's not a slam dunk to use Emacs file variables to enable this minor mode explicitly (for files that don't match the regex linked above); this is a separate conversation. See Specifying File Variables in the Emacs manual for more information. I use the following at the bottom of my files:

# Local Variables:
# eval: (ansible-doc-mode 1)
# eval: (add-to-list (quote company-backends) (quote company-ansible))
# eval: (ansible 1)
# End:

( P.S. Regarding your comment about testing Ansible roles with this Spacemacs layer, I don't think that is directly supported as a feature, but you could likely find ways to run test-kitchen or similar from Emacs. )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.