第4章 オーダープロセスワークフロー全体で置換可能な変数の有効化
オーダープロセスワークフローで使用する製品全体で変数を置き換えることができます。置換可能な変数を実装するには、Ansible Tower でジョブテンプレートのサーベイを作成または編集し、Automation Services Catalog の製品にアタッチされたサーベイで置換を有効にする必要があります。
置換形式および要件
置換可能な値は、{{substitution_express}}
形式で表され、波括弧と式の間にスペースは使用できません。置換に使用できる各変数の詳細は、Substitute variables を参照してください。
4.1. オーダープロセスワークフローへの置換可能な変数の実装
本セクションでは、本書に記載の Playbook の例を使用して、Playbook の Automation Services Catalog に公開するデータを置換可能な変数に合わせる方法を説明します。
4.1.1. before order プロセスを作成して製品オーダーへの値の指定
before order プロセスの Playbook before_order.yml
の例
# This playbook prints a simple debug message and set_stats - name: Echo Hello, world! hosts: localhost gather_facts: yes tasks: - debug: msg: "Hello, world!" - set_stats: data: expose_to_cloud_redhat_com_favorite_color: "orange"
この Playbook は、値が オレンジ
色の Playbook アーティファクト favorite_color
を Automation Services Catalog に戻します。ユーザー入力が必要ないため、Ansible Tower でジョブテンプレートサーベイを作成する必要はありません。代わりに、before オーダープロセス製品に設定された Automation Services Catalog の Survey を編集することにより、favorite_color
を製品 Playbook に渡すことができます。
4.1.2. 置換変数を使用するための 製品オーダー の設定
この製品 Playbook の例では、{{favorite_color}} の置換された変数を受け入れ、アーティファクト after_data を Automation Services Catalog に戻します。
Playbook product_order.yml
の例
# This playbook prints a simple debug message with given information - name: Echo Hello, world! hosts: localhost gather_facts: yes tasks: - debug: msg: "Hello, {{favorite_color}} world!" - set_stats: data: expose_to_cloud_redhat_com_after_data: "{{favorite_color}}"
favorite_color を *Answer Variable Name として設定する product_order.ymlPlaybook のジョブテンプレートを Ansible Tower に作成します。
以下を含む product_order.yml
ジョブテンプレートの Survey を作成します。
- Prompt フィールドに What is your favorite color? と入力します。
- Answer Variable Name フィールドに favorite_color と入力します。
- UPDATE をクリックします。
Automation Services Catalog の product order Survey を有効にして、before_order.yml
から渡された 'favorite_color' の値を使用します。
product order に割り当てられた Survey で、以下を行います。
以下の値でフィールドを更新します。
- Name: favorite_color
- Initial Value: {{before.before_order.artifacts.favorite_color}}
- Label: What is your favorite color?
- Placeholder: {{before.before_order.artifacts.favorite_color}}
- Disabled スイッチが有効になるように切り替えます。
- Substitution スイッチを有効になるように切り替えます。
これで、置換可能な変数として before_order.yml
Playbook から favorite_color
アーティファクトを使用するように product order を設定できました。
4.1.3. 製品オーダーから after_data
アーティファクトの値を受け入れるために after order 製品の設定
Surbey を使用して、代入変数を使用する after_order.yml
に、product_order.yml アーティファクト after_data
を渡します。
after order 製品の Playbook after_order.yml
の例
# This playbook prints a simple debug message with given information - name: Echo Hello, world! hosts: localhost gather_facts: yes tasks: - debug: msg: "{{after_data}}"
after_data を *Answer Variable Name として設定する after_order.yml Playbook のジョブテンプレートを Ansible Tower に作成します。
after_order.yml
ジョブテンプレートに割り当てられた Surveyで、以下を実行します。
- Prompt フィールドに Enter your after data と入力します。
- Answer Variable Name フィールドに after_data と入力します。
- UPDATE をクリックします。
Automation Services Catalog の after order Survey を有効にして、after_order.yml
から渡された after_data の値を使用します。
after order に割り当てられた Survey で、以下を行います。
以下の値でフィールドを更新します。
- Name: after_data
- Initial Value: {{product.artifacts.after_data}}
- Label: "Enter your after data"
- Placeholder: {{product.artifacts.after_data}}
- Disabled スイッチが有効になるように切り替えます。
- Substitution スイッチを有効になるように切り替えます。
Playbook は、ジョブテンプレートの実行時に after data に渡される値を表示します。