0
我試圖「清理」在Ansible變量中的空格(ansible-2.1.1.0-1.fc24.noarch)playbook和我雖然我會首先split()它然後再次加入('')。出於某種原因,這種做法是給我的錯誤如下: -/由空格分割字符串,然後在ansible/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()加入('')'deffierent?join('')'反正?謝謝! – jhutar
我已經用解釋更新了我的答案。 –