相关疑难解决方法(0)

用空格分割字符串,然后在ansible/jinja2中再次连接它

我试图在Ansible(ansible-2.1.1.0-1.fc24.noarch)剧本中的一个变量中"清理"空格,我虽然我先拆分()然后再加入('').由于某种原因,这种方法给我以下错误: - /

---
- 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(' ') }}"
...
Run Code Online (Sandbox Code Playgroud)

给我:

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, …
Run Code Online (Sandbox Code Playgroud)

jinja2 ansible

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

ansible ×1

jinja2 ×1