I am trying to pass blueprints inputs as environment variables to a python script (executed by script_plugin during one of the lifecycle operations of a node).
We are using Cloudify 3.1. My blueprint looks like below (trimmed it to show the required sections):
inputs:
sql_server_username:
type: string
default: ''
description: >
Enter SQL Server User Name
node_templates:
my_install:
type: my.nodes.Root
relationships:
- target: win2012r2
type: cloudify.relationships. contained_in
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: scripts/my/installer.py
inputs:
process:
env:
SQL_USERNAME: { get_input: sql_server_username }
and in my python script (installer.py) I am trying to access SQL_USERNAME
using os.environ.get("SQL_USERNAME", "DEFAULT")
. But I am always getting the default value even when I pass a custom value via inputs during deploy,
What should I change to be able to access the input parameters as environment vairables (from the inputs section of the blueprint) in the script?
After spending almost 24 hours, found out that if the script is a python script and eval_script is not set to false in the Process configuration options, the environment variables are not injected (atleast for v 3.1).
Thanks to Dan Kilman. The snippet below is from Ref# https://groups.google.com/d/msg/cloudify-users/mEAI9x9ivXQ/39Rg6KgKP4cJ
They are indeed not exposed as environment variables but are readily available as inputs by placing them in the top level inputs instead of the nested env.process and then doing something like
from cloudify.state import ctx_parameters as inputs
afterward, you can access these like this
# inputs in this case is just a sugared dict that allows top level key attribute-like access to the operation inputs # you could just as well do
inputs['LOAD_BALANCER_IP'] ``ctx.logger.info(inputs.LOAD_BALANCER_IP)
Wish this was explicitly stated in the docs ..