我想从主机中提取所有接口名称,然后打印该接口的所有信息。
--- # Fetches network interfaces with IPs
- hosts: hta
gather_facts: yes
become: yes
tasks
- debug: msg=" {{ ansible_interfaces|length }}"
register: num
- name: moving template over to server
template: src=templates/network.j2 dest=/root/network_info.txt
和network.j2文件
{% for int in ansible_interfaces %}
Interfaces: Interface-{{ int }}
Data: ansible_{{ int }}
{% endfor %}
到目前为止,我不能打印信息,Ansible接受我的输入ansible_{{ int }}作为文字。
发布于 2019-03-14 23:58:43
下面的剧本
- command: "ifconfig {{ item }}"
register: result
loop: "{{ ansible_interfaces }}"
- template:
src: template.j2
dest: int.txt
delegate_to: localhost
使用此模板
{% for int in result.results %}
Interfaces: Interface-{{ int.item }}
Data: {{ int.stdout }}
{% endfor %}
在本地主机上创建包含接口数据的文件int.txt。
https://stackoverflow.com/questions/55165106
复制相似问题