heat_template_version: rocky

description: >
  Template for nova's logging to files

parameters:
  ContainerNovaImage:
    description: image
    type: string
  NovaServiceName:
    description: service name
    type: string
  DeployIdentifier:
    default: ''
    type: string
    description: >
      Setting this to a unique value will re-run any deployment tasks which
      perform configuration on a Heat stack-update.

resources:

  InitLogContainerName:
    type: OS::Heat::Value
    properties:
      type: string
      value:
        str_replace:
          template: nova_SERVICE_init_log
          params:
            SERVICE: {get_param: NovaServiceName}

outputs:
  cmd_extra_args:
    description: Extra command line arguments for running the service in the container.
    value: ''
  config_settings:
    description: Extra hieradata needed to log to files in the host.
    value: null
  volumes:
    description: The volumes needed to log to files in the host.
    value:
      - /var/log/containers/nova:/var/log/nova
  docker_config:
    description: Extra containers needed for logging to files in the host.
    value:
      step_2:
        map_replace:
        - CONTAINERNAME:
            image: {get_param: ContainerNovaImage}
            net: none
            privileged: false
            user: root
            volumes:
              - /var/log/containers/nova:/var/log/nova:z
            command: ['/bin/bash', '-c', 'chown -R nova:nova /var/log/nova']
            environment:
              # NOTE: this should force this container to re-run on each
              # update (scale-out, etc.)
              TRIPLEO_DEPLOY_IDENTIFIER: {get_param: DeployIdentifier}
        - keys:
            CONTAINERNAME: {get_attr: [InitLogContainerName, value]}
  host_prep_tasks:
    description: Extra ansible tasks needed for logging to files in the host.
    value:
      - name: create persistent directories
        file:
          path: "{{ item.path }}"
          setype: "{{ item.setype }}"
          state: directory
        with_items:
          - { 'path': /var/log/containers/nova, 'setype': svirt_sandbox_file_t, 'mode': '0750' }
