From 193b95f2341f8a67ee3f755d675783febd60a6c4 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Wed, 2 Mar 2016 11:54:51 +0200
Subject: [PATCH] - Better YAML formatting in ansible-python. - Use code blocks
 instead of literal blocks.

---
 content/ansible-modules.rst |  4 +++-
 content/ansible-python.rst  | 30 +++++++++++++++++++-------
 content/pelican.rst         | 42 ++++++++++++++++++++++---------------
 3 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/content/ansible-modules.rst b/content/ansible-modules.rst
index 6595036..21c8996 100644
--- a/content/ansible-modules.rst
+++ b/content/ansible-modules.rst
@@ -26,7 +26,9 @@ there's no restriction on the hierarchy depth. In your playbook directory create
 a ``library`` directory (the Ansible default, so you can change this in
 ``ansible.cfg``) and create an empty ``__init__.py`` file inside that directory.
 Add a git submodule inside that directory and you're done. Let's see an
-example::
+example
+
+.. code:: shell
 
     git init ansible-modules
     cd ansible-modules
diff --git a/content/ansible-python.rst b/content/ansible-python.rst
index 445250e..5d1dbd5 100644
--- a/content/ansible-python.rst
+++ b/content/ansible-python.rst
@@ -7,13 +7,17 @@ Using Ansible as a Python module
 At my current employer we have several servers in production with various
 providers, some of them with multiple ip addresses. When configuring the
 firewall to allow traffic from other servers I reached for Ansible. The
-obvious solution was to use a nested loop, something like this: ::
+obvious solution was to use a nested loop, something like this:
+
+.. code:: yaml
 
     - name: Allow other servers
-      ufw: rule=allow from_ip={{ item[1] }}
+      ufw:
+        rule: allow
+        from_ip: '{{ item[1] }}'
       with_nested:
         - all_hosts
-        - {{ item.ansible_all_ipv4_addresses }}
+        - '{{ item.ansible_all_ipv4_addresses }}'
 
 However, this syntax is invalid (and other variations I tried). Using 'include'
 with 'with_items' is deprecated and I didn't manage to get it to work with
@@ -25,7 +29,9 @@ Incorperating Ansible in Python
 -------------------------------
 
 To retrieve all of the ip addresses I'd ran the setup module to gather the
-information ::
+information
+
+.. code:: python
 
     from ansible.runner import Runner
     struct = Runner (module_name='setup', pattern='all_hosts').run()
@@ -33,7 +39,9 @@ information ::
 Now we have a complex data structure that is the output of Ansible's fact
 gathering module. Running it in the interpeter and examining the structure is
 not hard at all and that is how I managed to write the following code to extract
-a list of all of our server's ip addresses. ::
+a list of all of our server's ip addresses.
+
+.. code:: python
 
     ipaddresses = []
     for host in struct['contacted']:
@@ -45,14 +53,18 @@ Putting that information to good use
             
 Now that we have a list of the ip addresses, we can start running Ansible
 commands right from with Python (just like we did) or build a playbook by
-outputing a YAML file. I chose the latter. ::
+outputing a YAML file. I chose the latter.
+
+.. code:: python
 
     from yaml import safe_dump
     doc = {'all_ipv4': ipaddresses}
     print (safe_dump (doc), file='vars.yml')
 
 This will create a vars.yml file with the all_ipv4 variable already defined
-there to be imported to any playbook and run. For example: ::
+there to be imported to any playbook and run. For example:
+
+.. code:: yaml
 
     ---
     - hosts: all_hosts
@@ -60,8 +72,10 @@ there to be imported to any playbook and run. For example: ::
         - vars.yml
       tasks:
         - name: Allow other servers
-          ufw: rule=allow from_ip={{ item }}
           with_items: all_ipv4
+          ufw:
+            rule: allow
+            from_ip: '{{ item }}'
 
 With this much little code we were able to query all of our hosts, extract the
 needed information and output it back to Ansible for further use. I see this as
diff --git a/content/pelican.rst b/content/pelican.rst
index 13e73cb..220c1c6 100644
--- a/content/pelican.rst
+++ b/content/pelican.rst
@@ -12,13 +12,17 @@ It's a pythonic tool that's easy to use and was a breeze to setup.
 
 Installing Pelican
 ------------------
-As Pelican is a static blog/ website generator, all we're doing is in your workstation. All you need to have server-wise is a bog-standard web server (like Apache or Nginx). Everything else is done on your local machine. I installed Pelican from Debian (it's currently available in testing) ::
+As Pelican is a static blog/ website generator, all we're doing is in your workstation. All you need to have server-wise is a bog-standard web server (like Apache or Nginx). Everything else is done on your local machine. I installed Pelican from Debian (it's currently available in testing)
 
-	$ apt-get install python-pelican fabric
+.. code:: shell
 
-Alternatively, you can use pip ::
+	apt-get install python-pelican fabric
 
-    $ pip install pelican fabric
+Alternatively, you can use pip
+
+.. code:: shell
+
+    pip install pelican fabric
 
 Creating a blog
 ---------------
@@ -64,26 +68,28 @@ Configuration
 
 In the blog directory there are the 2 configuration files: pelicanconf.py for configuring Pelican and publishconf.py for configuration that are only for publishing using Make or Fabric. Pelican also creates standard Makefile and fabfile.py for you. I've made the following modifications to pelicanconf.py: ::
 
-  TIMEZONE = 'Asia/Jerusalem'
-  PATH = "content"
-  DIRECT_TEMPLATES = ('index', 'archives')
-  DISPLAY_CATEGORIES_ON_MENU = False
-  DISPLAY_PAGES_ON_MENU = True
-  TAGS_SAVE_AS = ''
-  TAG_SAVE_AS = ''
-  STATIC_PATH = ['static']
+    TIMEZONE = 'Asia/Jerusalem'
+    PATH = "content"
+    DIRECT_TEMPLATES = ('index', 'archives')
+    DISPLAY_CATEGORIES_ON_MENU = False
+    DISPLAY_PAGES_ON_MENU = True
+    TAGS_SAVE_AS = ''
+    TAG_SAVE_AS = ''
+    STATIC_PATH = ['static']
 
 And to publishconf.py: ::
 
-  CATEGORY_FEED_ATOM = None
+    CATEGORY_FEED_ATOM = None
   
 I've set the timezone to mine (so that the time of published articles is correct), add everything under contents/static as static contents to be uploaded to the server, disabled showing of categories of articles and creating feeds for them, disabled saving of articles by tags and set pages (which are simple web pages unlike articles which are blog entries) to show on the menu. Next, themes. 
 
 Themes
 ------
-Pelican comes with a default theme (the same as used by Pelican's website) but I wanted something more understated so I took at look at `https://github.com/getpelican/pelican-themes <https://github.com/getpelican/pelican-themes>`_ and chose pelican-mockingbird. Cloned it ::
+Pelican comes with a default theme (the same as used by Pelican's website) but I wanted something more understated so I took at look at `https://github.com/getpelican/pelican-themes <https://github.com/getpelican/pelican-themes>`_ and chose pelican-mockingbird. Cloned it
 
-  $ git clone https://github.com/wrl/pelican-mockingbird.git
+.. code:: shell
+
+    git clone https://github.com/wrl/pelican-mockingbird.git
 
 and set the theme to that by adding the following to pelicanconf.py: ::
 
@@ -101,9 +107,11 @@ Create a ReStructedText file inside of contents. The filename is for personal us
     :author: <Insert your name here>
     :summary: <Insert summary here>
     
-After we added the content we want to upload it to our web server (I use fabric) ::
+After we added the content we want to upload it to our web server (I use fabric)
+
+.. code:: shell
 
-    $ fab publish
+    fab publish
     
 If you don't have keys set for the server it will ask you for your password to the server.
 Last thing, you can create pages, create a pages directory inside contents and save the files there. Their format is the same as articles but they'll have a somewhat template applied and they will be shown in the menu. A good example will an 'About Me' page.
-- 
GitLab