Questions/comments regarding a playbook

Hello

I'm coming from Puppet world and starting to play with Ansible devel branch.

I'm trying to "translate" a class for configuring nrsysmond and have
some questions/comments. Please see http://pastebin.com/RScspjRd

the "Bugs" section

the "Bugs" section
------------------
In line 11 I had to escape the '\1' because python was parsing it and
sending a '\u0001' char to sed. I think this should be documented in
both 'shell' and 'command' modules.

I'd highly recommend using the template module than relying on sed in
a playbook, for general reasons of idempotence.
It's far easier.

- template: src=... dest=...

Versus the 5 line stanza of only_if/ignore_errors/etc that you have there.

template module in line 3 complains if I add a 'state=file'.According to
the documentation template accepts everything accepted by file.

Yeah, that's true, it accepts all parameters that modify the file.
I think you are the first to try passing state :slight_smile:

the "Concepts" section
----------------------
1. In line 3 I had to create a template for one line. Is there any plan
to support including text in the yaml itself? I'm thinking in something
like Puppet's inline_template[1].

No immediate plans, but the whole "lookup" plugin system that powers
with_items could be easily hijacked to add that.

with_inline_template: "<string>"

could set $item appropriately. However, as I don't see many people
making use of this, I generally don't think it's something we would
add to core.
Lookup plugins are pluggable though, so you could add it if you wanted.

2. As can be seen I'm using "only_if: is_set('${newrelic_key}')" in
every task. This file in pastebin.com is included from main.yml so
something like this:

- include: tasks/nrsysmond.yml
  only_if: is_set(...)

Yeah, that's not going to happen like that, because of /when/ only_if
gets evaluated,

What seems to make more sense to me is to allow attaching an "only_if"
(well, the new 'when' operator coming in 0.9 is much more likely) to
the play itself, and that would in turn automatically attach the
conditional to all of the tasks below it.

vars:
  desired_state: "'file' if is_set('${newrelic_key}') else 'absent'"

but it didn't work, desired_state got the expression as is, it wasn't
evaluated. Recommendations?

only_if is for boolean conditionals only. Unlike Puppet, we do not
want things to start looking like a programming language. That's the
whole
point of Ansible. In this case you would have two tasks, one with a
conditional, one with the inverse conditional.

You can save only_if terms in variables, so it is as simple as:

vars:
    newrelic_set: "is_set('$newrelic_key')"

only_if: "not $newrelic_set"

AND

only_if: "$newrelic_set"

again, having conditions attached to plays also makes sense. Maybe later.

4. I could write a module for getting the current key if
/etc/newrelic/nrsysmond.cfg is present but I think it's overkill for
just a line match on a file, no matter how easy is to write a module. In
Puppet I have:

exec {"nrsysmond-config --set license_key=${sysmond::key}":
  unless => "grep -E '^license_key=${sysmond::key}'
/etc/newrelic/nrsysmond.cfg"
}

You can use the "shell/command" module to do this already, and
register the variable -- to avoid writing a module.

command: blarg
register: $newrelic_key

and later use

${newrelic_key.stdout} anywhere later on down the line.