我使用ubuntu20,ansible 2.9.6,我想自動化cisco設備,我的ansible相關設定如下
/etc/ansible/hosts有這些
[david-ios]
10.0.0.109
10.0.0.110
[david-ios:vars]
ansible_network_os=ios
ansible_user=david
ansible_password=1qaz@WSX
name: show ip interface br
hosts: david-ios
gather_facts: false
tasks:
name: show users
hosts: david-ios
gather_facts: false
tasks:
執行結果如下
david@ubuntu20:/etc/ansible$ sudo ansible-playbook ios.yml
PLAY [show ip interface br] ****************************************************
TASK [show ip interface br] ****************************************************
changed: [10.0.0.110]
changed: [10.0.0.109]
TASK [debug] *******************************************************************
ok: [10.0.0.109] => {
"print_output.stdout_lines": [
"",
"Interface IP-Address OK? Method Status Protocol",
"FastEthernet0/0 10.0.0.109 YES DHCP up up ",
"FastEthernet1/0 unassigned YES unset administratively down down "
]
}
ok: [10.0.0.110] => {
"print_output.stdout_lines": [
"",
"Interface IP-Address OK? Method Status Protocol",
"FastEthernet0/0 10.0.0.110 YES DHCP up up ",
"FastEthernet1/0 unassigned YES unset administratively down down "
]
}
PLAY [show users] **************************************************************
TASK [show users] **************************************************************
changed: [10.0.0.109]
changed: [10.0.0.110]
TASK [debug] *******************************************************************
ok: [10.0.0.109] => {
"print_output.stdout_lines": [
"",
" Line User Host(s) Idle Location",
" 0 con 0 idle 00:05:18 ",
"* 2 vty 0 david idle 00:00:00 10.0.0.104",
"",
" Interface User Mode Idle Peer Address"
]
}
ok: [10.0.0.110] => {
"print_output.stdout_lines": [
"",
" Line User Host(s) Idle Location",
" 0 con 0 idle 00:05:19 ",
"* 2 vty 0 david idle 00:00:00 10.0.0.104",
"",
" Interface User Mode Idle Peer Address"
]
}
PLAY RECAP *********************************************************************
10.0.0.109 : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
10.0.0.110 : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
david@ubuntu20:/etc/ansible$
雖然可執行成功,但我目前設定會導致執行結果,在相同的指令執行不同host,再執行下個指令,
以我案例就是所有cisco設備先執行show ip int br,再執行show users。
然而我想要先在相同(即一個)cisco設備執行所有指令後(show ip int br、show users),
再對下一個cisco設備執行所有指令,請問大大們我應該如何調整?
或者這其實受限於ansible設計?