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:
>
> I have several roles that create various numbers of security groups.
>
> I have another role that creates an instance.
>
> I want the second role to be re-usable, and to be usable with the roles
> that create security groups.
>
> So I want the second role to attach a list of security groups to the
> instance it creates.
>
> The role that creates security groups thus has to be able to somehow
> return a list of security groups.
>
> My role creates security groups and registers eg sg_1, sg_2, sg_3 and so
> on.
>
> How can I create a list variable? Something like sgs: [sg_1.group_id,
> sg_2.group_id, sg_3.group_id] ?
>
> The variable cannot be created inside the role that creates the instance,
> as that would bind it too closely to the role that creates the security
> groups. It has to be created inside the role that creates the security
> groups.
>
> Or is there some other way to achieve this?
>
> Regards, K.
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7fe8ae5b-47a8-44c5-b9f8-cd9179d36a07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.