问题
Using in my script file .sh:
ctx logger info $(ctx instance host_ip)
I get the private IP of my instance on AWS. How do I get the public IP?
回答1:
Short answer is that as of right now you cannot, but the feature is planned.
More complete answer -
ctx.instance.host_ip maps to a compute node instance's runtime property ctx.instance.runtime_properties[ip]. By convention this is a private ip address.
This property is set if the current node is of, or is derived from, the type cloudify.nodes.Compute, or if the current node has a relationship of, or is derived from, the type cloudify.relationships.contained_in that has a target of node type, or derived from, cloudify.nodes.Compute.
AWS plugin sets the runtime property on node type cloudify.aws.nodes.Instance ctx.instance.runtime_properties['public_ip_address'].
In the meantime, the best solution is to us a script in a lifecycle operation to set a runtime property on the needed node that need's the public IP such as you will find here.
回答2:
You can get public IP address in the following way:
public_address=$(ctx instance public_ip_address)
ctx logger info "Public IP address is ${public_address}"
来源:https://stackoverflow.com/questions/33791696/how-to-get-ip-public-aws-in-cloudify