Hey Chris,

I typically use modules to do targeted tasks instead of trying to batch
multiple operations into a single task, but in the interest of educating
myself, I took a swing at putting your example into a single task. The
following should give you some ideas.


- name: a play
  hosts: all
  connection: local

  tasks:
      - name: TextExpander Settings Directory
        file:
            path: "/tmp/Application\ Support/TextExpander/"
            state: "directory"

      - name: TextExpander Settings Symlink
        file:
            src: "/tmp/Dropbox/TextExpander/Settings.textexpander"
            dest: "/tmp/Application\
Support/TextExpander/Settings.textexpander"
            state: "link"
            force: "yes"

- name: a play
  hosts: all
  connection: local

  tasks:
      - name: TextExpander Settings
        file:
            path: "{{ item.path|default(omit) }}"
            state: "{{ item.state }}"
            src: "{{ item.src|default(omit) }}"
            dest: "{{ item.dest|default(omit) }}"
            force: "{{ item.force|default(omit) }}"
        with_items:
            - path: "/tmp/Application\ Support/TextExpander2/"
              state: "directory"
            - src: "/tmp/Dropbox/TextExpander2/Settings.textexpander"
              dest: "/tmp/Application\
Support/TextExpander2/Settings.textexpander"
              state: "link"
              force: "yes"



The first play is just a mock-up of the example you provided.

The second play is the same example (I just changed the directory name to
"TextExpander2") with a single task used with a loop and jinja's omit
filter. I'm looping over a list of dictionaries and using omit on values
that I know may not exist. State always exists.

Now, does this make it look cleaner? Well, that's subjective so I'll let
you decide. You could take the content in the with_items list and put it in
a vars file to make the play itself look smaller (and allow your list of
things to grow nearly unbounded).

When I run it on my box over here it goes off without a hitch and gives me
(what I think) are the results you're looking for




SEA-ML-RUPP1:ui trupp$ ansible-playbook -i localhost, ok.yaml

PLAY [a play]
*****************************************************************

GATHERING FACTS
***************************************************************
ok: [localhost]

TASK: [TextExpander Settings Directory]
***************************************
changed: [localhost]

TASK: [TextExpander Settings Symlink]
*****************************************
changed: [localhost]

PLAY [a play]
*****************************************************************

GATHERING FACTS
***************************************************************
ok: [localhost]

TASK: [TextExpander Settings]
*************************************************
changed: [localhost] => (item={'path': '/tmp/Application
Support/TextExpander2/', 'state': 'directory'})
changed: [localhost] => (item={'dest': '/tmp/Application
Support/TextExpander2/Settings.textexpander', 'src':
'/tmp/Dropbox/TextExpander2/Settings.textexpander', 'state': 'link',
'force': 'yes'})

PLAY RECAP
********************************************************************
localhost                  : ok=5    changed=3    unreachable=0    failed=0

SEA-ML-RUPP1:ui trupp$




Hope that helps.

-tim

On Mon, Jan 4, 2016 at 7:10 PM, Chris White <[email protected]>
wrote:

> Took a different approach to this and tried to set this up as a Bash
> command instead and discovered that it also requires the creation of the
> directory structure in a separate step so I'm guessing there's no way to
> make Ansible do it if it isn't built directly into the module. Looks like
> I'll just need to add a second task unless anyone else has an idea.
>
> On Monday, January 4, 2016 at 8:02:50 PM UTC-7, Chris White wrote:
>>
>> So I take it no one else is doing this kind of thing? I pinged Ansible on
>> Twitter and they directed me here.
>>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/8244a346-7ea2-4cf1-86c8-10b6796f4b42%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/8244a346-7ea2-4cf1-86c8-10b6796f4b42%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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAB0Zv8iELpOcEveBEXb2R3FkEaamkTyd9mmPP8t%2BzeEbbFj5Cg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to