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