user21696
user21696

Reputation: 1

Not able to execute lifecycle operation using script plugin

I'm trying to learn how to use script plugin. I'm following script plugin docs here but not able to make it work.

I've tried to use the plugin in two ways. The first, when cloudify.interface.lifecycle.start operation is mapped directly to a script:

tosca_definitions_version: cloudify_dsl_1_3
imports:
  - 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
  Import_Project:
    type: cloudify.nodes.WebServer
    capabilities:
      scalable:
        properties:
          default_instances: 1
    interfaces:
      cloudify.interfaces.lifecycle:
        start:
          implementation: scripts/create_project.sh
          inputs: {}

The second with a direct mapping:

tosca_definitions_version: cloudify_dsl_1_3
imports:
  - 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
  Import_Project:
    type: cloudify.nodes.WebServer
    capabilities:
      scalable:
        properties:
          default_instances: 1
    interfaces:
      cloudify.interfaces.lifecycle:
        start:
          implementation: script.script_runner.tasks.run
          inputs:
            script_path: scripts/create_project.sh

I've created a directory named scripts and placed the below create_project.sh script in this directory:

#! /bin/bash -e

ctx logger info "Hello to this world"
hostname

I'm getting errors while validating the blueprint. Error when operation is mapped directly to a script:

[2019-04-13 13:29:40.594] [DEBUG] DslParserExecClient - got output from dsl parser Could not extract plugin from operation mapping 'scripts/create_project.sh', which is declared for operation 'start'. In interface 'cloudify.interfaces.lifecycle' in node 'Import_Project' of type 'cloudify.nodes.WebServer'
  in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-27O0e1t813N6as
  in line: 3, column: 2
  path: node_templates.Import_Project
  value: {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'scripts/create_project.sh', 'inputs': {}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}

Error when using a direct mapping:

[2019-04-13 13:25:21.015] [DEBUG] DslParserExecClient - got output from dsl parser node 'Import_Project' has no relationship which makes it contained within a host and it has a plugin 'script' with 'host_agent' as an executor. These types of plugins must be installed on a host
  in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-279QCz2CV3Y81L
  in line: 2, column: 0
  path: node_templates
  value: {'Import_Project': {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'script.script_runner.tasks.run', 'inputs': {'script_path': 'scripts/create_project.sh'}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}}

What is missing to make this work?

Upvotes: 0

Views: 149

Answers (1)

vizwiz
vizwiz

Reputation: 11

I also found the Cloudify Script Plugin examples from their documentation do not work: https://docs.cloudify.co/4.6/working_with/official_plugins/configuration/script/

However, I found I can make the examples work by adding an executor line in parallel with the implementation line to override the host_agent executor as follows:

tosca_definitions_version: cloudify_dsl_1_3
imports:
  - 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
  Import_Project:
    type: cloudify.nodes.WebServer
    capabilities:
      scalable:
        properties:
          default_instances: 1
    interfaces:
      cloudify.interfaces.lifecycle:
        start:
          implementation: scripts/create_project.sh
          executor: central_deployment_agent
          inputs: {}

Upvotes: 1

Related Questions