首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Jinja模板中的Ansible multiple facts

Jinja模板中的Ansible multiple facts
EN

Stack Overflow用户
提问于 2019-03-14 22:30:18
回答 1查看 624关注 0票数 1

我想从主机中提取所有接口名称,然后打印该接口的所有信息。

--- # 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 }}作为文字。

EN

回答 1

Stack Overflow用户

发布于 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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55165106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档