silly trick: you can use variables in the "- name:" part of a playbook

i realize itfits how yaml and jinja2 works so probably obvious to many of you. never thought about it until after doing this and seeing the result. could make for more readable output.

example please, didn’t get it. Thanks

i realize itfits how yaml and jinja2 works so probably obvious to many of
you. never thought about it until after doing this and seeing the result.
could make for more readable output.

example please, didn't get it. Thanks

Something like this:

  - name: "{{ action }} the hosts"
    hosts: all
    tasks:
      - name: "{{ action }} a host"
        debug: var=action

Then you can run the playbook with '--extra-vars action=smite' or
whatever, and you'll get output like

  PLAY [smite the hosts] *********************************************************

  TASK [setup] *******************************************************************
  ok: [host-01]

  TASK [smite a host] ************************************************************
  ok: [host-01] => {
      "action": "smite"
  }

As in that example, this also works in tasks, although not with things
like with_items, e.g.

  tasks:
    - name: "{{ item }} a host"
      debug: var=item
      with_items: [bump, set, spike]

says

  TASK [{{ item }} a host] *******************************************************
  ok: [dom-use-util-01] => (item=bump) => {
      "item": "bump"
  }
  ok: [dom-use-util-01] => (item=set) => {
      "item": "set"
  }
  ok: [dom-use-util-01] => (item=spike) => {
      "item": "spike"
  }

because the three items all get processed within one task.

                                      -Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.