iT邦幫忙

0

ansible的執行順序問題

  • 分享至 

  • xImage

我使用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

/etc/ansible/ios.yml有這些

  • name: show ip interface br
    hosts: david-ios
    gather_facts: false

    tasks:

    • name: show ip interface br
      raw: "show ip interface brief"
      register: print_output
    • debug: var=print_output.stdout_lines
  • name: show users
    hosts: david-ios
    gather_facts: false

    tasks:

    • name: show users
      raw: "show users"
      register: print_output
    • debug: var=print_output.stdout_lines

執行結果如下
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設計?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
補覺鳴詩
iT邦高手 1 級 ‧ 2024-07-24 09:19:58
I.T. Wang iT邦新手 1 級 ‧ 2024-07-24 22:08:51 檢舉

謝謝您的協助,我再試試看

我要發表回答

立即登入回答