3

OpenStack 'Heat' 的编排引擎可以部署计算资源和配置软件,称为 HOT 模板。github上有很多例子: https ://github.com/openstack/heat-templates/tree/master/hot

heat 模板是用 YAML 编写的,我们可以使用这种语法部署模板

heat stack-create my_first_stack -f heat_1a.yaml

您还可以将模板文件直接上传到 OpenStack 仪表板。但是,这是我的问题,许多模板还将包括在部署后运行的 powershell 脚本的 shell 脚本 - 我们如何将这些脚本上传到 OpenStack 以包含在堆栈中?

例如,这里是 Microsoft SQL 服务器模板的目录列表

C:\heat-templates\hot\Windows\MSSQLServer>ls
MSSQL.ps1  MSSQL.psm1  MSSQL.yaml  Tests  heat-powershell-utils.psm1

Heat 客户端只会将 YAML 文件作为参数,那么我们如何处理这些脚本呢?

谢谢,罗布。

4

2 回答 2

4

参考 heat 的模板指南: http ://docs.openstack.org/developer/heat/template_guide/software_deployment.html

本质上,在 yaml 模板文件中定义的资源可以使用从指定文件名读取字符串的“get_file”指令。因此,当您调用 heat 客户端您的 MSSQL.yaml 时,您的 heat 客户端会解析它,并且无论在哪里看到带有文件名作为参数的“get_file”,它都会从该文件中读取。

使用上述链接中的“get_file”的示例:

...
the_server:
  type: OS::Nova::Server
  properties:
    # flavor, image etc
    user_data:
      str_replace:
        template: {get_file: the_server_boot.sh}
        params:
          $FOO: {get_param: foo}
于 2016-04-18T22:39:08.857 回答
1

有时,我们需要根据 HEAT 模板中提供的参数创建脚本,并在 Stack 创建后执行。

对于这种需求,我们可以使用下面提到的模式。一旦 VM 启动并处于 cloud-init 阶段,这将创建并执行脚本。

services-cloud-init:
    type: OS::Heat::CloudConfig
    properties:
        cloud_config:
            timezone: {get_param: time_zone}
            write_files:
              - path: /tmp/change_password.sh
                owner: root:root
                permissions: '0777'
                content: |
                          #!/bin/bash
                          echo -e "pwd\npwd" | passwd cloud-user

              - path: /run/change_timezone.sh
                owner: root:root
                permissions: '0777'
                content: |
                          #!/bin/bash
                          ln -sf /usr/share/zoneinfo/timezone /etc/localtime

            runcmd:
              - echo "Executing change_timezone"
              - /tmp/change_timezone.sh
              - echo "Executing change_password"
              - /tmp/change_password.sh
              - reboot
            bootcmd:
              - echo "Boot Completed"
于 2018-05-23T14:43:52.977 回答