0

2 つの変数ファイルがあります。最初のファイルには定数が含まれ、2 番目のファイルには生成された出力からの変数が含まれます。

最初のファイル.yml

---
prefix: test

セカンドファイル.yml

---
test_variable: 12345

では、test_variable を呼び出したいのですが、変数の形成は firstfile.yml からの連結であり、連結ではない必要があります。"{{ test_variable }}"

例:

- hosts: localhost
  connection: local

  vars: 

    constants: firstfile.yml
    variables: seconfile.yml

  vars_files:

    - [ "{{ constants }}, {{ variables }}"

  tasks:
    name: test_name
    field: "{{ prefix }}_variable"

エラー:'test_variable' does not exist</Message></Error></Errors>

4

1 に答える 1

0

Ansible で変数を表示するには、デバッグモジュールを使用する必要があります。

すべてではなく、各テンプレート式の大括弧を引用する必要があります。また、複数の変数ファイルを含める場合は、ファイルごとに個別の行を使用するか、リストを使用できます。2 つの方法を組み合わせないでください。

変更後のプレイブック:

---

- hosts: localhost
  connection: local
  vars: 
    constants: firstfile.yml
    variables: secondfile.yml
  vars_files: ["{{ constants }}", "{{ variables }}"]
  tasks:
    - debug: var="{{ prefix }}_variable"

結果:

TASK: [debug var="{{ prefix }}_variable"] ************************************* 
ok: [localhost] => {
    "var": {
        "test_variable": "12345"
    }
}
于 2015-09-08T09:20:19.977 に答える