I haven’t used it for a while and don’t have my working copy any more…
Can you run it with -v so that we can see the results of ec2_vol (you may need to strip out your secret keys from the results - I recommend using environment variables for the secrets where you can). I suspect it’s something to do with ec2_volumes.results.
You may get some more information using
action: debug msg={{ec2_volumes}}
if you’re using v1.4
TASK: [Print out the volume ids] **********************************************
ok: [localhost] => {“msg”: “{udevice:”}
TASK: [Tag the volume] ********************************************************
fatal: [localhost] => One or more undefined variables: ‘str object’ has no attribute ‘volume_id’
FATAL: all hosts have already failed – aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/root/cv.retry
Comparing how ec2 and ec2_vol process their results, I suspect this is a bug in ec2_vol - it’s just printing the json results, not running module.exit_json with the results. I was sure I had this working although I went over to another approach (creating the volume at instance creation time and tagging it then, which I’m still hoping to get accepted at some point - https://github.com/ansible/ansible/pull/4534)
If you raise this as a bug on github I can look at fixing how this works - hopefully someone will accept it relatively quickly.
Ok, this was a red herring, apologies. There is nothing actually wrong with using print json.dumps rather than module.exit_json (I tested both versions)
You need to use
debug msg=“{{ec2_volumes}}”
(note the quotes around the variable)
Perhaps the problem is the use of the with_items with a single result (obviously with_items would work with a one element array, but may well not work with a single result)
I would try the following (note that I rename the register variable to reflect that it is a single result):
name: Tag the volume
local_action: ec2_tag resource={{ec2_volume.volume_id}} region=us-east-1 state=present aws_access_key={{aa_key}} aws_secret_key={{as_key}}
args:
tags:
name: test