Hi Ansible developers,

I've been wondering about something. Ansible's syntax for module arguments
is key=value parameters, all on a single line. This then needs to be
parsed, and the key=value elements properly separated.

Wouldn't it be much nicer if the module parameters were also just written
in YAML syntax? For example:

- hosts: all
   tasks:
     - name: blah
       yum:
         - name: package
         - state: installed

And it might even be an idea to pass the playbook through Jinja first,
allowing things like:

- name: blah
    yum:
{% for pkg in packages %}
     - name: "{{ pkg }}"
     - state: installed
{% endfor %}

We would not need the "when:" conditional, or the shlex module to split
key=value pairs. This would allow taking full advantage of Jinja's
templating features.

Could this be an idea for Ansible 2.0?

Regards,
Anand

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/34adf7d7-5d32-459d-a3a3-8fe02d049271%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Tom Bamford at Feb 2, 2015 at 12:25 am
    Hi Anand

    You actually can (and I prefer to) write your playbooks with that kind of
    plain YAML syntax. e.g.

    - hosts: localhost
       tasks:
         - name: blah
           yum:
             name:
               - mypackage
               - otherpackage
             state: present
         - name: blurh
           copy:
             src: myfile
             dest: /tmp/myfile
             mode: 0640
             owner: me

    It gets more interesting with the shell and command modules

    - hosts: localhost
       tasks:
         - name: run this
           shell: mycommand
           args:
             creates: /tmp/artefact
             chdir: /path/to/dir
             executable: /bin/bash

    On 2 February 2015 at 02:15, Anand Buddhdev wrote:

    Hi Ansible developers,
    I've been wondering about something. Ansible's syntax for module arguments
    is key=value parameters, all on a single line. This then needs to be
    parsed, and the key=value elements properly separated.

    Wouldn't it be much nicer if the module parameters were also just written
    in YAML syntax? For example:

    - hosts: all
    tasks:
    - name: blah
    yum:
    - name: package
    - state: installed

    And it might even be an idea to pass the playbook through Jinja first,
    allowing things like:

    - name: blah
    yum:
    {% for pkg in packages %}
    - name: "{{ pkg }}"
    - state: installed
    {% endfor %}

    We would not need the "when:" conditional, or the shlex module to split
    key=value pairs. This would allow taking full advantage of Jinja's
    templating features.

    Could this be an idea for Ansible 2.0?

    Regards,
    Anand

    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/34adf7d7-5d32-459d-a3a3-8fe02d049271%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/34adf7d7-5d32-459d-a3a3-8fe02d049271%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.


    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAAnNz0NnD0x08r0ODROxGEf8sQtFFKKe2ACVux6EXysgvC7uzQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Anand Buddhdev at Feb 2, 2015 at 12:33 am
    Thanks Tom! I didn't realise it was already possible! So I can also use
    Jinja functions in a playbook to include/exclude some parameters based on
    facts?
    On Monday, 2 February 2015, Tom Bamford wrote:

    Hi Anand

    You actually can (and I prefer to) write your playbooks with that kind of
    plain YAML syntax. e.g.

    - hosts: localhost
    tasks:
    - name: blah
    yum:
    name:
    - mypackage
    - otherpackage
    state: present
    - name: blurh
    copy:
    src: myfile
    dest: /tmp/myfile
    mode: 0640
    owner: me

    It gets more interesting with the shell and command modules

    - hosts: localhost
    tasks:
    - name: run this
    shell: mycommand
    args:
    creates: /tmp/artefact
    chdir: /path/to/dir
    executable: /bin/bash

    On 2 February 2015 at 02:15, Anand Buddhdev <arhbkb@gmail.com
    wrote:

    Hi Ansible developers,
    I've been wondering about something. Ansible's syntax for module
    arguments is key=value parameters, all on a single line. This then needs to
    be parsed, and the key=value elements properly separated.

    Wouldn't it be much nicer if the module parameters were also just written
    in YAML syntax? For example:

    - hosts: all
    tasks:
    - name: blah
    yum:
    - name: package
    - state: installed

    And it might even be an idea to pass the playbook through Jinja first,
    allowing things like:

    - name: blah
    yum:
    {% for pkg in packages %}
    - name: "{{ pkg }}"
    - state: installed
    {% endfor %}

    We would not need the "when:" conditional, or the shlex module to split
    key=value pairs. This would allow taking full advantage of Jinja's
    templating features.

    Could this be an idea for Ansible 2.0?

    Regards,
    Anand

    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com
    <javascript:_e(%7B%7D,'cvml','ansible-project%2bunsubscribe@googlegroups.com');>
    .
    To post to this group, send email to ansible-project@googlegroups.com
    <javascript:_e(%7B%7D,'cvml','ansible-project@googlegroups.com');>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/34adf7d7-5d32-459d-a3a3-8fe02d049271%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/34adf7d7-5d32-459d-a3a3-8fe02d049271%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.


    --
    You received this message because you are subscribed to a topic in the
    Google Groups "Ansible Project" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/ansible-project/dGJRlrohfmY/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    ansible-project+unsubscribe@googlegroups.com
    <javascript:_e(%7B%7D,'cvml','ansible-project%2bunsubscribe@googlegroups.com');>
    .
    To post to this group, send email to ansible-project@googlegroups.com
    <javascript:_e(%7B%7D,'cvml','ansible-project@googlegroups.com');>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/CAAnNz0NnD0x08r0ODROxGEf8sQtFFKKe2ACVux6EXysgvC7uzQ%40mail.gmail.com
    <https://groups.google.com/d/msgid/ansible-project/CAAnNz0NnD0x08r0ODROxGEf8sQtFFKKe2ACVux6EXysgvC7uzQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CANbPJF%3Dt1LfT26dsGs%3DfPPdzUBF-SPGXEHnNbPtv%3D4YXV6xvzw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Giovanni Tirloni at Feb 2, 2015 at 12:34 am

    On Mon, 02 Feb 2015 02:24 +0200, Tom Bamford wrote:
    You actually can (and I prefer to) write your playbooks with that kind of plain YAML syntax. e.g.
    Same here. Otherwise I've found sometimes I have to decide which one to
    use, where to put quotes, etc. I just go 100% YAML and the INI files.

    Ansible's syntax with the equal signs is more concise but I don't mind
    the extra lines with YAML.

    Giovanni

    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1422837243.2608918.221747525.0F40620A%40webmail.messagingengine.com.
    For more options, visit https://groups.google.com/d/optout.
  • Anand Buddhdev at Feb 2, 2015 at 9:58 am
    Hi Tom,

    I just tried the syntax you suggested.

    My very simple playbook is:

    - hosts: myhost
       tasks:
         - name: install packages
            yum:
              name:
                - screen
                - tmux
              state: installed

    However, when I run this, I get an errors:

    SUDO-SUCCESS-ziubbkxxzglhrtsmdmekoixffubflanc
    Traceback (most recent call last):
       File "/tmp/ansible-tmp-1422870182.84-7050423984136/yum", line 2402, in
    <module>
         main()
       File "/tmp/ansible-tmp-1422870182.84-7050423984136/yum", line 832, in main
         disablerepo, disable_gpg_check)
       File "/tmp/ansible-tmp-1422870182.84-7050423984136/yum", line 717, in
    ensure
         items = pkgspec.split(',')
    AttributeError: 'list' object has no attribute 'split'


    Are you certain that plain YAML syntax works for modules?

    On 2 February 2015 at 01:24, Tom Bamford wrote:

    Hi Anand

    You actually can (and I prefer to) write your playbooks with that kind of
    plain YAML syntax. e.g.

    - hosts: localhost
    tasks:
    - name: blah
    yum:
    name:
    - mypackage
    - otherpackage
    state: present
    - name: blurh
    copy:
    src: myfile
    dest: /tmp/myfile
    mode: 0640
    owner: me

    It gets more interesting with the shell and command modules

    - hosts: localhost
    tasks:
    - name: run this
    shell: mycommand
    args:
    creates: /tmp/artefact
    chdir: /path/to/dir
    executable: /bin/bash

    On 2 February 2015 at 02:15, Anand Buddhdev wrote:

    Hi Ansible developers,
    I've been wondering about something. Ansible's syntax for module
    arguments is key=value parameters, all on a single line. This then needs to
    be parsed, and the key=value elements properly separated.

    Wouldn't it be much nicer if the module parameters were also just written
    in YAML syntax? For example:

    - hosts: all
    tasks:
    - name: blah
    yum:
    - name: package
    - state: installed

    And it might even be an idea to pass the playbook through Jinja first,
    allowing things like:

    - name: blah
    yum:
    {% for pkg in packages %}
    - name: "{{ pkg }}"
    - state: installed
    {% endfor %}

    We would not need the "when:" conditional, or the shlex module to split
    key=value pairs. This would allow taking full advantage of Jinja's
    templating features.

    Could this be an idea for Ansible 2.0?

    Regards,
    Anand

    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/34adf7d7-5d32-459d-a3a3-8fe02d049271%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/34adf7d7-5d32-459d-a3a3-8fe02d049271%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.


    --
    You received this message because you are subscribed to a topic in the
    Google Groups "Ansible Project" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/ansible-project/dGJRlrohfmY/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/CAAnNz0NnD0x08r0ODROxGEf8sQtFFKKe2ACVux6EXysgvC7uzQ%40mail.gmail.com
    <https://groups.google.com/d/msgid/ansible-project/CAAnNz0NnD0x08r0ODROxGEf8sQtFFKKe2ACVux6EXysgvC7uzQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CANbPJFmvAxuLXhJt7DDK9FZz5D7bEuKC0X5FcTrTWwoRGVhj0A%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Giovanni Tirloni at Feb 2, 2015 at 10:10 am

    On Mon, 02 Feb 2015 10:58 +0100, Anand Buddhdev wrote:
    Hi Tom,

    I just tried the syntax you suggested.

    My very simple playbook is:

    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name:
    - screen
    - tmux
    state: installed
    - hosts: myhost
       tasks:
         - name: install packages
           yum:
             name: "{{ item }}"
             state: latest
           with_items:
             - screen
             - tmux


    Useful reading:
    http://docs.ansible.com/playbooks_loops.html

    Giovanni

    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1422871831.2610733.221884249.32774E87%40webmail.messagingengine.com.
    For more options, visit https://groups.google.com/d/optout.
  • Anand Buddhdev at Feb 2, 2015 at 10:34 am
    Hi Giovanni,

    Your suggestion works. But I think what I was trying to say is that
    Ansible's playbook syntax is mixed. Wouldn't it be cool if it were pure
    YAML, with Jinja templating? Then it would allow something like:

    - hosts: myhost
       tasks:
         - name: install packages
            yum:
              name:
                - tmux
                - screen
    {% if ansible_distribution_major_version == '6' %}
                - lsof
    {% endif %}

    Instead of inventing ansible-specific loops, we could just use the power of
    Jinja templating.
    On 2 February 2015 at 11:10, Giovanni Tirloni wrote:
    On Mon, 02 Feb 2015 10:58 +0100, Anand Buddhdev wrote:
    Hi Tom,

    I just tried the syntax you suggested.

    My very simple playbook is:

    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name:
    - screen
    - tmux
    state: installed
    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name: "{{ item }}"
    state: latest
    with_items:
    - screen
    - tmux


    Useful reading:
    http://docs.ansible.com/playbooks_loops.html

    Giovanni

    --
    You received this message because you are subscribed to a topic in the
    Google Groups "Ansible Project" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/ansible-project/dGJRlrohfmY/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/1422871831.2610733.221884249.32774E87%40webmail.messagingengine.com
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CANbPJFn3ZbnsGfm05q1ZqCYPtpOQGyzPL9qTumhgOGhgcezZHw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Giovanni Tirloni at Feb 2, 2015 at 11:19 am

    On Mon, 02 Feb 2015 11:34 +0100, Anand Buddhdev wrote:
    Hi Giovanni,

    Your suggestion works. But I think what I was trying to say is that
    Ansible's playbook syntax is mixed. Wouldn't it be cool if it were pure
    YAML, with Jinja templating? Then it would allow something like:

    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name:
    - tmux
    - screen
    {% if ansible_distribution_major_version == '6' %}
    - lsof
    {% endif %}

    Instead of inventing ansible-specific loops, we could just use the power
    of
    Jinja templating.
    As an Ansible newbie, I have struggled with understanding where it's
    Ansible or Jinja2 doing the parsing. So I can surely related to that. On
    the other hand, Ansible tries to be simple and the looping constructs,
    IMHO, are easy to work with and have a concise syntax.

    I don't have enough experience with Ansible to suggest where it should
    go next.

    In my so far very limited knowledge of Ansible, I would suggest
    encapsulating these things in different roles (e.g. common_debian,
    common_centos6, common_centos7). It seems more idiomatic in Ansible,
    based on the examples I've seen so far.


    Giovanni

    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1422875948.2632340.221904057.7C4B5D3D%40webmail.messagingengine.com.
    For more options, visit https://groups.google.com/d/optout.
  • Anand Buddhdev at Feb 2, 2015 at 3:17 pm
    On 2 February 2015 at 12:19, Giovanni Tirloni wrote:

    As an Ansible newbie, I have struggled with understanding where it's
    Ansible or Jinja2 doing the parsing. So I can surely related to that. On
    the other hand, Ansible tries to be simple and the looping constructs,
    IMHO, are easy to work with and have a concise syntax.
    Hi Giovanni,

    My thinking is similar. Ansible playbooks are parsed in a strange way. Some
    parts of it are plain YAML, whereas other parts are run through the Jinja2
    templating engine. This is confusing.

    I was reading Salt documentation, and saw that Salt's state files are just
    plain YAML, but the entire YAML file is passed through Jinja2, so that any
    loops and other variable things are done by Jinja2, and this is
    conceptually neater than Ansible's current mix of Jinja2 and Ansible's own
    declarative language.

    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CANbPJF%3Dkj8fBVnwp4QxnJpJQAV5VFaQ%2BBfj9Csc8T9Yo6r6s8w%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Tom Bamford at Feb 2, 2015 at 11:48 am
    Hi Anand

    Are you sure your indenting is correct? Here’s an example from one of my
    role task files, known working with Ansible v1.8.2 (packages trimmed for
    brevity)

    ---
    - name: Install packages (apt)
       apt:
         pkg:
           - bash-completion
           - bind9utils
           - vim-nox
           - zsh
         state: present
       when: ansible_os_family == 'Debian'

    - name: Install packages (yum)
       yum:
         name:
           - bind-utils
           - byobu
           - vim-enhanced
           - zsh
         state: present
       when: ansible_os_family == 'RedHat'


    On 2 February 2015 at 12:34, Anand Buddhdev wrote:

    Hi Giovanni,

    Your suggestion works. But I think what I was trying to say is that
    Ansible's playbook syntax is mixed. Wouldn't it be cool if it were pure
    YAML, with Jinja templating? Then it would allow something like:

    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name:
    - tmux
    - screen
    {% if ansible_distribution_major_version == '6' %}
    - lsof
    {% endif %}

    Instead of inventing ansible-specific loops, we could just use the power
    of Jinja templating.
    On 2 February 2015 at 11:10, Giovanni Tirloni wrote:

    On Mon, 02 Feb 2015 10:58 +0100, Anand Buddhdev <arhbkb@gmail.com>
    wrote:
    Hi Tom,

    I just tried the syntax you suggested.

    My very simple playbook is:

    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name:
    - screen
    - tmux
    state: installed
    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name: "{{ item }}"
    state: latest
    with_items:
    - screen
    - tmux


    Useful reading:
    http://docs.ansible.com/playbooks_loops.html

    Giovanni

    --
    You received this message because you are subscribed to a topic in the
    Google Groups "Ansible Project" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/ansible-project/dGJRlrohfmY/unsubscribe
    .
    To unsubscribe from this group and all its topics, send an email to
    ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/1422871831.2610733.221884249.32774E87%40webmail.messagingengine.com
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/CANbPJFn3ZbnsGfm05q1ZqCYPtpOQGyzPL9qTumhgOGhgcezZHw%40mail.gmail.com
    <https://groups.google.com/d/msgid/ansible-project/CANbPJFn3ZbnsGfm05q1ZqCYPtpOQGyzPL9qTumhgOGhgcezZHw%40mail.gmail.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAAnNz0N8%2B7hF3fuOJ7zXgFpSQ0j%3DjP5aH4hR8nLmMM%3D%3DXxg_Zw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Anand Buddhdev at Feb 2, 2015 at 3:13 pm
    Hello Tom,

    I am certain that my syntax and indentation is correct. I have created a
    test role, called packages, and in the main.yml file of the tasks directory
    of this role, I have:

    ---

    - name: install packages

       yum:

         name:

           - screen

           - tmux

           - lsof

         state: present
    However, running this role results in:

    SUDO-SUCCESS-fwkqifljtkdcrlzyrnukmprtmiczpknk
    Traceback (most recent call last):
       File "/tmp/ansible-tmp-1422889693.47-234739679264274/yum", line 2402, in
    <module>
         main()
       File "/tmp/ansible-tmp-1422889693.47-234739679264274/yum", line 832, in
    main
         disablerepo, disable_gpg_check)
       File "/tmp/ansible-tmp-1422889693.47-234739679264274/yum", line 717, in
    ensure
         items = pkgspec.split(',')
    AttributeError: 'list' object has no attribute 'split'


    $ ansible --version

    ansible 1.8.2

       configured module search path = None


    On 2 February 2015 at 12:48, Tom Bamford wrote:

    Hi Anand

    Are you sure your indenting is correct? Here’s an example from one of my
    role task files, known working with Ansible v1.8.2 (packages trimmed for
    brevity)
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CANbPJF%3DFeY0nKgu1HGSsbfyqZU%3DdmQmHJZQkXSSCkPXPRFYQ_g%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Tom Bamford at Feb 2, 2015 at 11:52 am
    Jinja templating doesn’t work in playbooks in that way. Lots of variable
    constructs are actually parsed with jinja2, so you can do stuff like

    - set_fact:
         myvar: "{% if something %}this{% else %}that{% endif %}"

    As Giovanni mentioned, there are numerous looping constructs for things
    like task repetition. Playbooks are declarative, so it wouldn’t really be
    right to build them from a template.

    On 2 February 2015 at 12:34, Anand Buddhdev wrote:

    Hi Giovanni,
    Your suggestion works. But I think what I was trying to say is that
    Ansible's playbook syntax is mixed. Wouldn't it be cool if it were pure
    YAML, with Jinja templating? Then it would allow something like:

    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name:
    - tmux
    - screen
    {% if ansible_distribution_major_version == '6' %}
    - lsof
    {% endif %}

    Instead of inventing ansible-specific loops, we could just use the power
    of Jinja templating.
    On 2 February 2015 at 11:10, Giovanni Tirloni wrote:

    On Mon, 02 Feb 2015 10:58 +0100, Anand Buddhdev <arhbkb@gmail.com>
    wrote:
    Hi Tom,

    I just tried the syntax you suggested.

    My very simple playbook is:

    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name:
    - screen
    - tmux
    state: installed
    - hosts: myhost
    tasks:
    - name: install packages
    yum:
    name: "{{ item }}"
    state: latest
    with_items:
    - screen
    - tmux


    Useful reading:
    http://docs.ansible.com/playbooks_loops.html

    Giovanni

    --
    You received this message because you are subscribed to a topic in the
    Google Groups "Ansible Project" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/ansible-project/dGJRlrohfmY/unsubscribe
    .
    To unsubscribe from this group and all its topics, send an email to
    ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/1422871831.2610733.221884249.32774E87%40webmail.messagingengine.com
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/CANbPJFn3ZbnsGfm05q1ZqCYPtpOQGyzPL9qTumhgOGhgcezZHw%40mail.gmail.com
    <https://groups.google.com/d/msgid/ansible-project/CANbPJFn3ZbnsGfm05q1ZqCYPtpOQGyzPL9qTumhgOGhgcezZHw%40mail.gmail.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.


    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAAnNz0Onf2c6ngT08UTypz1mer6ty_QcBiDYkkMUUX33%3DAeeVg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Anand Buddhdev at Feb 2, 2015 at 3:21 pm
    On 2 February 2015 at 12:52, Tom Bamford wrote:

    Hi Tom,
    Jinja templating doesn’t work in playbooks in that way. Lots of variable
    constructs are actually parsed with jinja2, so you can do stuff like

    - set_fact:
    myvar: "{% if something %}this{% else %}that{% endif %}"

    As Giovanni mentioned, there are numerous looping constructs for things
    like task repetition. Playbooks are declarative, so it wouldn’t really be
    right to build them from a template.
    I understand this, and it is exactly what I am trying to discuss here. Why
    can't one build a playbook from a template? I think plain YAML is just fine
    for declarative statements. Or am I missing a use case?

    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CANbPJFmqH0-W%2BEHV%3DY%2B5_EX9fAbxKWRXYajWmpbkrVgA-cCAHQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedFeb 2, '15 at 12:15a
activeFeb 2, '15 at 3:21p
posts13
users3

People

Translate

site design / logo © 2022 Grokbase