Ask Your Question
1

heat circular exception - get server ip in user_data

asked 2015-01-15 04:08:52 -0600

agti gravatar image

updated 2015-01-16 02:17:15 -0600

Hi all, I'm trying to test heat templates, but when I reference the IP of a server in the user_data definition of the server itself I see a CircularDependencyException...

Which is the best way to do what I have in mind (basically modify a config file on my server with the actual IP). Here the snippet related with the error:

serv:
    type: OS::Nova::Server
    properties:
      name: serv
      image: image-new
      flavor: m1.small
      key_name: { get_param: KeyName }
      user_data:                                                        
        str_replace:                                                    
          template: |                                                   
            #!/bin/bash -x
        echo hola >> /home/ubuntu/hola.txt
            sudo sed -i s/\<privateIP\>/"%server_ip%"/g /etc/hola/config
          params:       
            "%server_ip%": {get_attr: [serv, first_address]}         
      networks: 
        - port: { get_resource: server_port }

ISSUE UPDATE

Is there a way to extract thos info directly from the heat template?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2015-01-15 11:02:27 -0600

NoNoNoo gravatar image

updated 2015-01-26 14:33:55 -0600

zaneb gravatar image

You can extract it executing some command in the instances.

For example:

/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

An update on my previous response:

Openstack heat documentation https://wiki.openstack.org/wiki/Heat/... describe your case:

If the UserData script needs to know the private IP address of the instance, it cannot be resolved by Fn::GetAtt(instance, "PrivateIp") since it is not available when the UserData file is resolved by the Heat engine.

The solution provided is execute the command curl -s http://169.254.169.254/latest/meta-data/local-ipv4 in the instance to extract the private ip

edit flag offensive delete link more

Comments

Thanks for your answer! But I imagine (maybe I'm wrong) there is a cleaner way to extract that kind of info directly from the heat template...

agti gravatar imageagti ( 2015-01-16 02:15:06 -0600 )edit

THANKS A LOT!

agti gravatar imageagti ( 2015-01-16 02:58:37 -0600 )edit
2

answered 2015-01-27 12:13:58 -0600

rmarrine gravatar image

In Icehouse I have used the following with success:

heat_template_version: 2013-05-23
parameters:
  node_hostname:
    type: string
  image:
    type: string
  flavor:
    type: string
  keypair:
    type: string
  private_net:
    type: string
  floating_net:
    type: string
resources:
  theNode:
    type: OS::Nova::Server
    properties:
      name: {get_param: node_hostname}
      key_name: {get_param: keypair}
      image: {get_param: image}
      flavor: {get_param: flavor}
      networks:
        - port : { get_resource: node_server_port }
      user_data:
        str_replace:
          template:  |
            #!/bin/sh
            echo MYIP `uname -n` >> /etc/hosts
          params:
            MYIP : {get_attr: [node_server_port, fixed_ips, 0, ip_address]}
  node_server_port:
    type: OS::Neutron::Port
    properties:
      network_id: {get_param: private_net}
  node_floating_ip:
    type: OS::Neutron::FloatingIP
    properties:
       floating_network_id: {get_param: floating_net}
       port_id: { get_resource: node_server_port }
edit flag offensive delete link more

Comments

thank you. i had the same problem.so i want to do the same with the floating ip adqress haw can i do?

binou gravatar imagebinou ( 2015-03-24 04:38:43 -0600 )edit
0

answered 2015-03-24 04:38:21 -0600

binou gravatar image

thank you. i had the same problem.so i want to do the same with the floating ip adqress haw can i do?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2015-01-15 04:08:52 -0600

Seen: 1,562 times

Last updated: Mar 24 '15