How to skip local_action if file exists?

464 views
Skip to first unread message

Stuart Reynolds

unread,
Jul 9, 2014, 10:46:10 PM7/9/14
to ansible...@googlegroups.com
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 :(
  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
   
###
   
## How to prevent running if {{cluster_name}}/{{key_name}}.pem exists
   
###

 
- name: Ensure key file exists locally
    local_action
: copy content="{{result.key.private_key}}" dest="{{cluster_name}}/{{key_name}}.pem"
   
when: "result.changed"

 
- name: Ensure key file is added to SVN
    local_action
: command "svn add {{cluster_name}}/{{key_name}}.pem"
   
when: "result.changed"


Michael DeHaan

unread,
Jul 10, 2014, 8:24:32 AM7/10/14
to ansible...@googlegroups.com
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



--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/94c86594-b3e5-4b1a-937e-be0585b0c624%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stuart Reynolds

unread,
Jul 10, 2014, 2:23:15 PM7/10/14
to ansible...@googlegroups.com
Nifty. Thx.
Reply all
Reply to author
Forward
0 new messages