0

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?

Tiago Rolim
  • 65
  • 1
  • 11

2 Answers2

2

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.

earthmant
  • 259
  • 1
  • 4
  • Edited my script file "set-mongo-url.sh" typing "ctx logger info $(ctx source instance runtime_properties public_ip_address)" and the error occurred: ERROR: Exception raised on operation [script_runner.tasks.run] invocation Traceback (most recent call last): File "/home/ubuntu/cloudify.mysql_host_41962/env/local/lib/python2.7/site-packages/cloudify/decorators.py", line 125, in wrapper result = func(*args, **kwargs)... – Tiago Rolim Nov 19 '15 at 23:14
  • https://github.com/tiagorol/cloudify-wordpress/blob/master/scripts/crawler/start-monitoring.sh – Tiago Rolim Nov 19 '15 at 23:15
0

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}"
Tunaki
  • 132,869
  • 46
  • 340
  • 423