Ask Your Question
2

HOT Template - How to use global parameters ?

asked 2015-06-30 01:54:59 -0500

Gaurav.Sangamnerkar gravatar image

updated 2015-06-30 07:04:30 -0500

For e.g. I am provisioning 2 machines using 1 heat template, I want the /etc/hosts file of both the servers to populate with IP addresses of both the hosts. Any clue on how can I achieve this ? parameters defined in user data for server 1 can be made global so that can be used in server 2 as well ?

Sample template:

Blockquote

    heat_template_version: 2013-05-23
resources:
  serverA:
    type: OS::Nova::Server
    properties:
      image: Linux-image
      flavor: m1.medium
      networks:
      - network: xxxxxx-xxxxx-xxxx-xxxx
      user_data: |
        #!/bin/bash
        export NIC=eth0
        export IP=`ifconfig $intfc | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
        export HOSTNAME=`hostname`
        export DOMAIN=TEST
        #Fix the etc/hosts file
        tee -a /etc/hosts <<EOF
        $IP $HOSTNAME $HOSTNAME.$DOMAIN
        EOF

  serverB:
    type: OS::Nova::Server
    depends_on: serverA
    properties:
      image: Linux-image
      flavor: m1.medium
      networks:
      - network: xxxxx-xxx-xxxx-xxxx
      user_data: |
        #!/bin/bash
        export NIC1=eth0
        export IP1=`ifconfig $intfc | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
        export HOSTNAME1=`hostname`
        export DOMAIN1=TEST
        #Fix the etc/hosts file
        tee -a /etc/hosts <<EOF
        $IP $HOSTNAME $HOSTNAME.$DOMAIN    <<<<<<<<<< IP address of first server
        $IP1 $HOSTNAME1 $HOSTNAME1.$DOMAIN1  <<<<<<<<<<<< IP address of second server
        EOF
 outputs:
 serverA:
   description:
     IP Address of the deployed instance
   value:
     get_attr: [serverA, first_address]
 serverB:
   description:
     IP Address of the deployed instance
   value:
     get_attr: [serverB, first_address]
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2015-06-30 10:04:09 -0500

fgorbat gravatar image

updated 2015-06-30 13:15:24 -0500

To set variable value, you have to use str_replace intrinsic function. In your particular case, get_attr should take [serverA, first_address]

Here is brief example

resources:

  the_server:
    type: OS::Nova::Server
    properties:
      # flavor, image etc
      user_data:
        str_replace:
          template: |
            #!/bin/bash
            echo "IP1-address IP1"
            echo "IP2-address IP2"
            # ...
          params:
            IP1: { get_attr: [serverA, first_address] }
            IP2: { get_attr: [serverB, first_address] }

Good luck!

edit flag offensive delete link more
0

answered 2015-07-01 06:49:38 -0500

Gaurav.Sangamnerkar gravatar image

updated 2015-07-01 07:00:52 -0500

Hello, Thanks a lot for your response. It did work & solve 1 problem, meaning now my serverB can understand the serverA IP by using str_replace function in serverB.

however if I put the str_replace for serverA, it lands in circular dependency error.

ERROR: Remote error: CircularDependencyException HT-CB4FFD8 Circular Dependency Found: {Server "serverB": {Server "serverA"}, Server "serverA": {Server "serverB"}}

I thought this is because serverB depends on serverA however even after removing the dependency same error persists. Am I missing something ?

Here is how the template looks like now ..

heat_template_version: 2013-05-23
resources:
  serverA:
    type: OS::Nova::Server
     properties:
      image: Linux-image
      flavor: m1.medium
      networks:
      - network: xxxxxx-xxxxx-xxxx-xxxx
      user_data: 
         str_replace:
            template: |
               #!/bin/bash
              export NIC=eth0
              export IP=`ifconfig $intfc | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
              export HOSTNAME=`hostname`
              export DOMAIN=TEST
              #Get the IP address
              tee -a /tmp/ip.txt <<EOF
              serverA IP address is $IP
              serverB IP address is IP2
              EOF
           params:
              IP2: { get_attr: [serverB, first_address]}

  serverB:
    type: OS::Nova::Server
    properties:
      image: Linux-image
      flavor: m1.medium
      networks:
      - network: xxxxx-xxx-xxxx-xxxx
      user_data: 
         str_replace:
           template: |
              #!/bin/bash
              export NIC=eth0
              export IP=`ifconfig $intfc | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
              export HOSTNAME=`hostname`
              export DOMAIN=TEST
              #Get the IP address 
              tee -a /tmp/ip.txt <<EOF
              serverB IP address is $IP    
              serverA IP address is IP1
              EOF
           params:
              IP1: { get_attr: [serverA, first_address]}
 outputs:
 serverA:
   description:
     IP Address of the deployed instance
   value:
     get_attr: [serverA, first_address]
 serverB:
   description:
     IP Address of the deployed instance
   value:
     get_attr: [serverB, first_address]
edit flag offensive delete link more

Comments

Hi, How did you solved it? I am facing the same problem, where one "OS::Nova::Server"s need to know the local ips of each other, Please response Thanks

CRS gravatar imageCRS ( 2017-07-16 12:57:44 -0500 )edit

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-06-30 01:54:59 -0500

Seen: 1,864 times

Last updated: Jul 01 '15