1. 程式人生 > >Ansible 使用HUAWEI ne_command模組執行檔案中的命令

Ansible 使用HUAWEI ne_command模組執行檔案中的命令

命令列檔案內容:注意行結束使用逗號

cat cmds.txt
system,
inter gi0/2/0,
disp thi inter,
 

playbook內容:

---

- name: test file content
  hosts: atn2
  gather_facts: false
  connection: local
  vars:
    cmds: "{{ lookup('file', '<real path>/cmds.txt') }}"
    cli:
      transport: cli

  tasks:
  - name: can exec ?
    ne_command:
      commands: "{{ cmds }}"
      provider: "{{ cli }}"
    register: rst

  - debug: var=rst