Building an Environment

An Environment file is a YAML file that augments a template deployment with global definitions, resource management, and parameter lists. There are two main sections, parameters and resource_registry, that allow you to define default values for expected parameters and customize resources to override template resources.

You may have access to more than one domain, or project, which may contain different resources, such as an image. You can use the same template simply by changing the values in the environment file to accommodate the new location.

To deploy a template with an environment file:

$ openstack stack create <STACK_NAME> -t <TEMPLATE.yaml> -e <ENVIRONMENT_FILE.yaml>

You can add sections for global parameters, encrypted parameters, merge strategies, and a list of endpoints for stack events. See Environments in the OpenStack Template Guide.

Use Case: Define a parameter value for a template

If your template requires multiple parameter values at runtime, it may be useful to organize your parameter list using an environment file. Building on the example in Using Parameters with a Template, use an environment file to overwrite the key_name parameter.

  1. Create the environment file with a parameters section and add a value for the key_name parameter used in the previous example.

    parameters:
      key_name: new_key
    
  2. Create the stack using the environment file. You do not have to include the expected key_name parameter because you defined it in the environment file.

    $ openstack stack create sampleStackInstance -t sampleTemplate.yaml -e environment.yaml
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | id                  | <stack_id>                           |
    | stack_name          | sampleStackInstance                  |
    | description         | Template to launch an instance       |
    | creation_time       | 2017-06-20T22:44:59                  |
    | updated_time        | None                                 |
    | stack_status        | CREATE_IN_PROGRESS                   |
    | stack_status_reason | Stack CREATE started                 |
    +---------------------+--------------------------------------+
    
  3. Show the instance information to verify the key name used.

    $ openstack server show sampleStackInstance
     +-----------------------------+-------------------------------------------------+
     | Field                       | Value                                           |
     +-----------------------------+-------------------------------------------------+
     | OS-DCF:diskConfig           | MANUAL                                          |
     | OS-EXT-AZ:availability_zone | <AZ>                                            |
     | OS-EXT-STS:power_state      | Running                                         |
     | OS-EXT-STS:task_state       | None                                            |
     | OS-EXT-STS:vm_state         | active                                          |
     | OS-SRV-USG:launched_at      | 2017-06-20T23:00:00.000000                      |
     | OS-SRV-USG:terminated_at    | None                                            |
     | accessIPv4                  |                                                 |
     | accessIPv6                  |                                                 |
     | addresses                   | sampleStackNetwork=10.0.7.9                     |
     | config_drive                |                                                 |
     | created                     | 2017-06-20T22:59:55Z                            |
     | flavor                      | m1.small (2)                                    |
     | hostId                      | <host_id>                                       |
     | id                          | <stack_id>                                      |
     | image                       | ubuntu-16.04.1-server-amd64 (<image_id>)        |
     | key_name                    | new_key                                         |
     | name                        | sampleStackInstance                             |
     | progress                    | 0                                               |
     | project_id                  | <project_id>                                    |
     | properties                  |                                                 |
     | security_groups             | name='default'                                  |
     | status                      | ACTIVE                                          |
     | updated                     | 2017-06-20T23:00:00Z                            |
     | user_id                     | <user_id>                                       |
     | volumes_attached            |                                                 |
     +-----------------------------+-------------------------------------------------+