Sorry - I've done it again; figured out a solution to my own problem AFTER posting a question.
Anyway, the answer is the set_facts: task. This lets you build a variable from other variables.
In the role that creates security groups, the last task is a set_fact: task that builds a list of the security group IDs. That fact (variable) is then available to the role that creates the instance, which can use it in the instance's group_id attribute.
For an instance that I had already created, I found a workaround by googling. The workaround was to use set_fact: after creating the security groups to create a space-delimited string of group IDs. The playbook itself (not the server role) then has an extra task, after the instance has already been built, of running an AWS CLI command to modify the instance ("aws ec2 modify-instance-attributes ...")
Regards, K.
On Tuesday, April 17, 2018 at 4:45:52 PM UTC+10, Karl Auer wrote: