Skip to content

Instantly share code, notes, and snippets.

@ralfbergs
Last active November 10, 2016 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfbergs/0cc62920f5df007597ade8aac2bf60a8 to your computer and use it in GitHub Desktop.
Save ralfbergs/0cc62920f5df007597ade8aac2bf60a8 to your computer and use it in GitHub Desktop.
env_devmgmt_name: "devmgmt"
env_mgmt_name: "mgmt"
env_preprod_name: "preprod"
env_prod_name: "prod"
---
dependencies:
- { role: aws.find-subnets, subnet_code_name: "pub_1" }
- { role: aws.find-subnets, subnet_code_name: "pub_2", when: env == env_mgmt_name }
- { role: aws.find-subnets, subnet_code_name: "be_1" }
- { role: aws.find-subnets, subnet_code_name: "be_2", when: env == env_mgmt_name }
- { role: aws.find-subnets, subnet_code_name: "be_deploy", when: env == env_mgmt_name }
- { role: aws.find-vpc }
- { role: aws.find-vpc, myenv: "preprod" }
- { role: aws.find-vpc, myenv: "prod" }
- { role: aws.find-vpc, myenv: "devenvs", when: env == env_devmgmt_name }
- { role: aws.find-sg, sg_name: "pub_jump"}
---
- hosts: localhost
vars:
env: "{{ env_devmgmt_name }}"
roles:
- aws/create
- name: "Launch instance for jumpbox: {{ owner }}_i_{{ env }}_jump_1"
ec2:
region: "{{ region }}"
image: "{{ ami_id }}"
count_tag:
Name: "{{ owner }}_i_{{ env }}_jump_1"
exact_count: 1
wait: yes
instance_type: "t2.micro"
key_name: "{{ ssh_key_name}}"
group_id:
- "{{ {{ env }}_sg_pub_jump.group_id }}"
- "{{ sg_ssh.group_id }}"
vpc_subnet_id: "{{ subnet_pub_1.id }}"
zone: "{{ az1 }}"
instance_tags:
Name: "{{ owner }}_i_{{ env }}_pub_jump_1"
Env: "{{ owner }}_{{ env }}"
Tier: "{{ owner }}_{{ env }}_pub"
register: i_jump_1
@halberom
Copy link

it would help to know what the format is, and where, {{ env }}sg..., sg_... variables are set. I am assuming they're dict's in a var file.

    group_id:
      - "{{ {{ env }}_sg_pub_jump.group_id }}"

The above won't work, nested {{}}. try

    group_id:
      - "{{ vars[env + '_sg_pub_jump']['group_id'] }}"

@halberom
Copy link

You've got some variables that are going to be strings

Name: "{{ owner }}_i_{{ env }}_pub_jump_1"

And some that I think you want to be interpolated

    group_id:
      - "{{ {{ env }}_sg_pub_jump.group_id }}"
      - "{{ sg_ssh.group_id }}"

which makes it a bit harder to parse/read

@ralfbergs
Copy link
Author

"env" is defined at the start of my Playbook.yml. The actual value is from group_vars/all, but it could be even written verbatim in the Playbook.yml,it doesn't matter.

@halberom
Copy link

obviously.

not asking what {{env}} is, asking what the format is of the dicts, and where they're set

@halberom
Copy link

otherwise it's unclear what's being interpolated, and what's just a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment