str_replace

The str_replace function replaces strings.

str_replace:
  template: <template string>
  params: <parameter mappings>
Element Required Description
template Yes Specifies the string that is the replacement source.
params Yes Specifies the mapping of the string for replacement. Other functions such as get_attr can be used.

Example specification of the str_replace function (1):

resources:
  my_instance:
    type: OS::Nova::Server

outputs:
  Login_URL:
    description: The URL to log into the deployed application
    value:
      str_replace:
        template: http://host/MyApplication
        params:
          host: { get_attr: [ my_instance, first_address ] }

In the above example, assuming the value returned by get_attr: [ my_instance, first_address ] is "10.0.0.1", the value of the output parameter "Login_URL" will be "http://10.0.0.1/MyApplication".

Example specification of the str_replace function (2):

parameters:
  DBRootPassword:
    type: string
    label: Database Password
    description: Root password for MySQL
    hidden: true

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      # general properties ...
      user_data:
        str_replace:
          template: |
            #!/bin/bash
            echo "Hello world"
            echo "Setting MySQL root password"
            mysqladmin -u root password $db_rootpassword
            # do more things ...
          params:
            $db_rootpassword: { get_param: DBRootPassword }

In the above example, in relation to user_data input for the compute resource, the str_replace function is used to replace the string "$db_rootpassword" with the value of the input parameter "DBRootPassword" of the template.