2323 ansible.builtin.copy :
2424 src : " {{ infra__terraform_template_dir }}/infra/"
2525 dest : " {{ infra__terraform_workspace_dir }}/workspace/infra"
26- # when: not workdir.stat.exists # TODO: This won't override if any changes to .tf are made. Good or Bad?
26+ # when: not workdir.stat.exists # NOTE: When uncommented won't override workspace dir if any changes to .tf are made.
2727
2828- name : Copy Terraform infra code to the artefact directory
2929 ansible.builtin.copy :
5959 ansible.builtin.file :
6060 path : " {{ infra__terraform_workspace_dir }}/workspace/infra"
6161 state : absent
62- when : infra__terraform_state_storage in ['remote_s3']
62+ when : infra__terraform_state_storage in ['remote_s3']
63+
64+ # If created Utility Instance via Terraform then
65+ # need to get it's info and add to an Ansible host group
66+ - name : Add Utility Instance to host group
67+ when : infra__create_utility_service
68+ block :
69+ - name : Discover the Utility Instance details
70+ community.aws.ec2_instance_info :
71+ region : " {{ infra__region }}"
72+ filters : " {{ __filters | items2dict }}"
73+ vars :
74+ __filters :
75+ - key : " tag:Name"
76+ value : " {{ infra__namespace }}*"
77+ register : __infra_utility_compute_discovered
78+
79+ - name : Add discovered Utility Instance to host group
80+ ansible.builtin.add_host :
81+ hostname : " {{__infra_utility_compute_discovered.instances[0].public_ip_address}}"
82+ ansible_user : " {{ infra__dynamic_inventory_images_default[infra__type][infra__dynamic_inventory_os].user }}"
83+ ansible_ssh_private_key_file : " {{ (infra__private_key_file == '') | ternary(omit, infra__private_key_file) }}"
84+ groupname : cldr_utility
0 commit comments