0
votes

I create Heat Template with Powershell commands and my template is not getting executed after adding deployment section. I have added this section to get output for commands.Below shown template I am using :

heat_template_version: 2016-10-14

description: Template to install HyperV Feature in Server

resources:
   floating_ip:
      type: OS::Neutron::FloatingIP
      properties:
         floating_network: Net_External_16

   instance:
      type: OS::Nova::Server
      properties:
         name: machine2
         flavor: LARGE
         networks:
            - network: 71xxxx85-8a24-475b-9xxc-169xxxxxbb0
         security_groups:
            - default
            - all_open
         block_device_mapping_v2:
            - device_name: /dev/vpa
              volume_id: {get_resource: volume}
              delete_on_termination: "true"
   volume:
      type: OS::Cinder::Volume
      properties:
         size: 25
         image: 51xxxxxbe-44e6-4206-920c-xxxxxxxxxx
         name: {get_param: volumename}

   ps_script:
      type: OS::Heat::SoftwareConfig
      properties:
         group: ungrouped
         config:
            str_replace:
               template: |
                  #ps1_sysnative
                  $log = New-Item "C:\check_file.txt" -Type File
                  start-sleep -s 20
                  install-windowsfeature -Name DNS -IncludeManagementTools
                  start-sleep -s 60
                  $pass = "_parameter_1_"
                  Add-content $log $pass

               params:
                  _parameter_1_: {get_param: parameter1}

   association:
      type: OS::Neutron::FloatingIPAssociation
      properties:
         floatingip_id: {get_resource: floating_ip}
         port_id: {get_attr: [instance, addresses, 71xxxxx85-8a24-4xxb-9xxc-16xxxx84bb0, 0, port]}

   deployment:
      type: OS::Heat::SoftwareDeployment
      properties:
         config: {get_resource: ps_script}
         server: {get_resource: instance }

outputs:
   instance_ip:
      description: Ipaddress
      value: {get_attr: [instance,addresses]}
   result:
     description: Checkoutput
     value: {get_attr: [deployent]}

If anybody tried this same method or any other solution they can provide to get output for powershell commands executed from Template.

1
What exact error you are getting? - sauumum
When you tried to launch the stack what is the error message you got ? - user5777975
Exactly error i am not getting. Stack Creation start but it stays in in progress state.By any chance if you have any sample template to get output of powershell command in heat template please share.it will be really helpful. - hgoyal
I was having a hard time finding clear resources about how to do this. Your post helped me, and I did get it working using the kvmahesh answer below. - quest4truth

1 Answers

1
votes

Add the line user_data_format: SOFTWARE_CONFIG under OS::Nova::Server properties :

instance:
  type: OS::Nova::Server
  properties:
     name: machine2
     flavor: LARGE
     networks:
        - network: 71xxxx85-8a24-475b-9xxc-169xxxxxbb0
     security_groups:
        - default
        - all_open
     block_device_mapping_v2:
        - device_name: /dev/vpa
          volume_id: {get_resource: volume}
          delete_on_termination: "true"
     user_data_format: SOFTWARE_CONFIG

This line is required when there is another resource for software configuration.

And also there is a typo in the output section deployent -> deployment

outputs:
  instance_ip:
    description: Ipaddress
    value: { get_attr: [instance,addresses] }
  result:
   description: Checkoutput
   value: { get_attr: [deployment] }

Note: Add the space after { and before }. For example :

 { get_resource: volume }