Ansible 使用多个变量与项目进行交互

Ansible 使用多个变量与项目进行交互,ansible,Ansible,只是想找点帮助 基本上,我正在尝试为我的计算机的每个网络接口创建一个文件,文件名是接口名和mac地址的组合。 e、 g 对于这些接口 带有mac 123-456-789的eth0 带有mac 987-654-321的eth1 带mac 456-123-789的eth2 我希望创建3个名为的文件: eth0_123-456-789 eth1987-654-321 eth2_456-123-789 我现在有这个剧本 - hosts: all tasks: - name: Create

只是想找点帮助

基本上,我正在尝试为我的计算机的每个网络接口创建一个文件,文件名是接口名和mac地址的组合。
e、 g

对于这些接口
带有mac 123-456-789的eth0
带有mac 987-654-321的eth1
带mac 456-123-789的eth2

我希望创建3个名为的文件:
eth0_123-456-789
eth1987-654-321
eth2_456-123-789

我现在有这个剧本

- hosts: all

  tasks:
    - name: Create files
      block:
        - name: This gets me a list of all eth* interfaces
          shell: ls /sys/class/net/ | grep eth
          register: eth_interface

        - name: This gets the mac address for each of those eth* interfaces
          command: cat /sys/class/net/{{ item }}/address
          with_items: "{{ eth_interface.stdout_lines }}"
          register: mac_address

        - name: Add mac address to its relevant file
          command: touch /tmp/"{{ item.mac }}"_"{{ item.eth }}"
          with_items: 
             - { eth: "{{ eth_interface.stdout_lines }}", mac: "{{ mac_address | json_query('results[*].stdout') }}" }

我希望每个接口都有3个单独的文件,但我得到了1个文件,名称如下: [u'123-456-789',u'987-654-321',u'456-123-789'][u'eth0',u'eth1',u'eth2']

如果我只使用一个变量,比如eth或mac,它似乎工作得很好,但是当我使用with_items循环将这两个变量一起使用时,它会中断

有人能帮忙吗?

下面的剧本

shell>cat pb.yml
-主机:本地主机
变量:
国际金融公司:[eth0,eth1,eth2]
mac:[AAA、BBB、CCC]
任务:
-文件:
状态:触摸
路径:“{{'tmp/'~item.0~'{'~item.1}”
循环:{{ifc | zip(mac)| list}}”
创造

shell>树tmp
tmp
├── eth0_AAA
├── eth1_BBB
└── 乙酰胆碱

哇,真管用。我已经为此抓挠了两天了,应该早点寻求帮助。非常感谢你的帮助!!!