ansible:在具有查找的行中包含_项
我要确保IP或域是已知主机::ansible:在具有查找的行中包含_项,ansible,Ansible,我要确保IP或域是已知主机:: - name: Ensure IP or domain is a known host lineinfile: > dest={{ home }}/.ssh/known_hosts create=yes state=present line="{{ lookup('pipe', 'ssh-keyscan -t ecdsa {{ item }}') }}" with_items: - 88.48.189.102 - my
- name: Ensure IP or domain is a known host
lineinfile: >
dest={{ home }}/.ssh/known_hosts create=yes
state=present line="{{ lookup('pipe', 'ssh-keyscan -t ecdsa {{ item }}') }}"
with_items:
- 88.48.189.102
- my.site.com
但是,{{item}}
在={{item}行中看不到
我得到:
getaddrinfo {{: Name or service not known
getaddrinfo item: Name or service not known
getaddrinfo }}: Name or service not known
您不需要内部大括号。您只需以以下方式将项连接为字符串:
{{lookup('pipe','ssh keyscan-t ecdsa'~item)}
或
{{lookup('pipe','ssh keyscan-t ecdsa'+item)}
但是,用户会说第一个是首选方法。您不需要内部大括号。您只需以以下方式将项连接为字符串:
{{lookup('pipe','ssh keyscan-t ecdsa'~item)}
或
{{lookup('pipe','ssh keyscan-t ecdsa'+item)}
但是专家说,第一种方法是首选方法