HuaweiSwitch / CloudEngine-Ansible

Ansible modules to automate HUAWEI CloudEngine switches
GNU General Public License v3.0
144 stars 51 forks source link

ce_command dealing with multiple hosts #6

Closed xqxrrz1ge2 closed 7 years ago

xqxrrz1ge2 commented 7 years ago

I am using this sample playbook:

---
- name: "sample book"
  hosts: localhost
  connection: local
  vars:
    cli:
      host: 172.19.2.1
      port: 22
      username: telnet
      password: Huawei@123
      transport: cli

  tasks:
  - name: run display version on remote devices
    ce_command:
      commands: display version
      provider: "{{ cli }}"

It works well when connecting a single CE switch. But how can I connect to a group of switches which I already defined in /etc/ansible/hosts in the first place? Assuming I have got group which is called SIS, when I replace the '172.19.2.1' with 'SIS', ansible is actually trying to connect 'SIS', but not the IP addresses listing in /etc/ansible/hosts. Plz help!

xqxrrz1ge2 commented 7 years ago

can somebody help, please?

QijunPan commented 7 years ago

@ticonci please try:

---
- name: "sample book"
  hosts: SIS
  connection: local
  vars:
    cli:
      host: '{{ inventory_hostname }}'
      port: 22
      username: telnet
      password: Huawei@123
      transport: cli

  tasks:
  - name: run display version on remote devices
    ce_command:
      commands: display version
      provider: "{{ cli }}"
xqxrrz1ge2 commented 7 years ago

it works. thx a lot