実現したいこと
変数(set_echo)はリスト型であり、下記の実行結果の様に6つの要素があります。
インデックスを複数指定して変数(set_echo)から配列の1番目(blue)、3番目(pink)、5番目(white)だけを選択して1行で出力させたいです。
set_echo[1]の様に1つだけインデックスを指定した場合には想定通りに1行に「blue」が出力されますが
set_echo[1, 3, 5] の様に複数指定するとエラーになります。
複数のインデックスを指定して下記の様に
一行に出力する方法をご教授頂けないでしょうか。
宜しくお願い致します。
期待する結果 ok: [localhost] => { "msg": [ "blue pink white" ]
発生している問題・エラーメッセージ
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: list object has no element (1, 3, 5). list object has no element (1, 3, 5)\n\nThe error appears to be in '/hoge.yml': line ?, column ?, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n with_sequence: start=0 end=1\n ^ here\n\nThere appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.\n"}
該当のソースコード
hohe.yml
1 - name: Echo 2 ansible.builtin.debug: 3 msg: "{{ set_echo }}"
ok: [localhost] => { "msg": [ "red", "blue", "black, "pink", "green", "white", "yellow" ] }
試したこと
msg: "{{ set_echo[1] }}"
ok: [localhost] => { "msg": "blue"
set_echo[1, 3, 5]
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: list object has no element (1, 3, 5). list object has no element (1, 3, 5)\n\nThe error appears to be in '/hoge.yml': line ?, column ?, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n with_sequence: start=0 end=1\n ^ here\n\nThere appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.\n"}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/08/30 04:50