How to skip local_action if file exists?

I’m trying to write a set of tasks to create an ec2 key_pair (if one doesn’t exist) and save it to svn.

Sadly, ec2_key is quite slow for me, even if the key already exists (maybe my network?). How can I prevent this task step from being run if I already have a key file locally?

… other modules include things like “creates:”. It would be nice if this logic was available the task level.

  • Stu
    PS: is there a complete documentation of a the keys in a task object? (name:, local_action:, … what else?)
    PPS. does anyone how to use variable in the text for a name?

`

  • name: “Create a key for {{ cluster_name }}” # Output includes the braces :frowning:
    hosts: localhost
    tags:
  • provision
    gather_facts: false # Prevents immediately logging into hosts
    vars:

Allow override of key name

key_name: “{{instance_key_name | default(cluster_name)}}”
tasks:

  • name: Ensure key file exists on AWS
    local_action:
    module: ec2_key
    name: “{{key_name}}”
    region: “{{instance_region}}”
    register: result

Start by trying something like this:

  • local_action: stat path=foo
    register: stat_result

  • debug: var=stat_result

Then use the stat_result in the conditional

Nifty. Thx.