私はAnsible(ansible-2.1.1.0-1.fc24.noarch)プレイブックの変数で空白をクリーンアップしようとしています。最初にsplit()それに続いて( '')に再度参加してください。何らかの理由でそのアプローチは、下の私にエラーを与えている: -/空白で文字列を分割してから、もう一度/ jinja2に参加してください。
---
- hosts: all
remote_user: root
vars:
mytext: |
hello
there how are
you?
tasks:
- debug:
msg: "{{ mytext }}"
- debug:
msg: "{{ mytext.split() }}"
- debug:
msg: "{{ mytext.split().join(' ') }}"
...
は私を与える:
TASK [debug] *******************************************************************
ok: [192.168.122.193] => {
"msg": "hello\nthere how are\nyou?\n"
}
TASK [debug] *******************************************************************
ok: [192.168.122.193] => {
"msg": [
"hello",
"there",
"how",
"are",
"you?"
]
}
TASK [debug] *******************************************************************
fatal: [192.168.122.193]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'join'\n\nThe error appears to have been in '.../tests.yaml': line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n msg: \"{{ mytext.split() }}\"\n - debug:\n ^here\n"}
私が間違ってやって上の任意のアイデア? フィールド 'args'には無効な値があり、未定義の変数が含まれているようです。エラーは 'リストオブジェクト'に属性 '結合'がありませんですが、useful filters文書によれば、それはうまくいくはずです。
くそー、私はそれを試したと確信していました。 'mytext.split()|はなぜですか?とにかく 'mytext.split()。join( '')からjoin( '')' deffierent?ありがとうございました! – jhutar
解説を解説付きで更新しました。 –