Skip to content

Indenting with Ansible YAML #1

Description

@blueyed

I am looking into indenting for Ansible's YAML, e.g.:


---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: pkg=httpd state=latest
  - name: write the apache config file
    template: src=/srv/httpd.j2 dest=/etc/httpd.conf
    notify:
    - restart apache
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
  handlers:
    - name: restart apache
      service: name=httpd state=restarted

(from http://docs.ansible.com/playbooks_intro.html)

With your plugin this gets indented as (using gg=G):


---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
    remote_user: root
    tasks:
      - name: ensure apache is at the latest version
        yum: pkg=httpd state=latest
        - name: write the apache config file
          template: src=/srv/httpd.j2 dest=/etc/httpd.conf
          notify:
            - restart apache
            - name: ensure apache is running (and enable it at boot)
              service: name=httpd state=started enabled=yes
              handlers:
                - name: restart apache
                  service: name=httpd state=restarted

According to http://www.yamllint.com/ it is valid.

I have tried to improve another plugin, specifically targeted at Ansible, before (chase/vim-ansible-yaml#36), but it looks like your approach might be better (using the context).

Apart from that you have tests.. :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions