Commit 3c84003d2117

Vincent Demeester <vincent.demeester@eileo.com>
2014-08-25 09:30:48
Add ansible
1 parent b47803b
Changed files (1)
.emacs.d
.emacs.d/emacs.org
@@ -1210,12 +1210,68 @@
       (require-package 'markdown-mode+)
     #+END_SRC
 
+
 *** DONE Yaml
 
     #+BEGIN_SRC emacs-lisp
       (require-package 'yaml-mode)
     #+END_SRC
 
+*** TODO Ansible
+
+[[http://docs.ansible.com/index.html][Ansible]] is a great automation tool I use to manage my servers and
+desktops.
+
+#+BEGIN_SRC emacs-lisp
+  (require-package 'ansible)
+  (add-hook 'yaml-mode-hook '(lambda () (ansible 1)))
+#+END_SRC
+
+The following snippet is taken from [[http://www.lunaryorn.com/2014/07/18/ansible-docs-in-emacs.html][lunaryorn article]] about getting
+ansible doc in emacs.
+
+#+BEGIN_SRC emacs-lisp
+  (defconst lunaryorn-ansible-doc-buffer " *Ansible Doc*"
+    "The Ansible Doc buffer.")
+
+  (defvar lunaryorn-ansible-modules nil
+    "List of all known Ansible modules.")
+
+  (defun lunaryorn-ansible-modules ()
+    "Get a list of all known Ansible modules."
+    (unless lunaryorn-ansible-modules
+      (let ((lines (ignore-errors (process-lines "ansible-doc" "--list")))
+            modules)
+        (dolist (line lines)
+          (push (car (split-string line (rx (one-or-more space)))) modules))
+        (setq lunaryorn-ansible-modules (sort modules #'string<))))
+    lunaryorn-ansible-modules)
+
+  (defun lunaryorn-ansible-doc (module)
+    "Show ansible doc for MODULE."
+    (interactive
+     (list (ido-completing-read "Ansible Module: "
+                                (lunaryorn-ansible-modules)
+                                nil nil nil nil nil
+                                (thing-at-point 'symbol 'no-properties))))
+    (let ((buffer (get-buffer-create lunaryorn-ansible-doc-buffer)))
+      (with-current-buffer buffer
+        (setq buffer-read-only t)
+        (view-mode)
+        (let ((inhibit-read-only t))
+          (erase-buffer)
+          (call-process "ansible-doc" nil t t module))
+        (goto-char (point-min)))
+      (display-buffer buffer)))
+#+END_SRC
+
+Let's bind it.
+
+#+BEGIN_SRC emacs-lisp
+  (eval-after-load 'yaml-mode
+    '(define-key yaml-mode-map (kbd "C-c h a") 'lunaryorn-ansible-doc))
+#+END_SRC
+
 *** DONE vim
 
     I tend to use vim for quick edit and other stuff and have a decent