I have situation where i fetch some ip address on the fly with this play, when env variable is passed as prod, i have to fetch ip in a diff way then when i am in QA env.
If env is prod the 1st play would get ip address and store in register "kafkaip" and i have put a when condition on the 2nd play it gets skipped which is fine as the env is diff.
But although its skip the 2nd play, it wipes out the register value and my set_fact fails,, any way to overcome below scenario.
- name: Get the Kafka InstancesPrivateIps
local_action: shell aws cloudformation describe-stacks --stack-name "{{ stack_kafka }}" --query "Stacks[*].Outputs[?OutputKey=='KafkaLink'].OutputValue"
register: kafkaip
when:
- stack_kafka is defined
- name: Get the Kafka InstancesPrivateIps New Automation.
shell: |
aws ec2 describe-instances --filter "Name=tag:StackName,Values=KafkaCluster" --query 'Reservations[].Instances[].PrivateIpAddress' --output text > /tmp/kafka_ip.txt
register: kafkaip
when:
- stack_kafka is defined
- ( deployment_env == "QA" )
delegate_to: localhost
- name: setting kafka_host.
set_fact:
kafka_host: "{{ kafkaip.stdout }}"
when: stack_kafka is defined