1. 程式人生 > >例項學習ansible系列(10)常用模組之script

例項學習ansible系列(10)常用模組之script

知識點:使用script模組可以實現到物件節點上執行本機指令碼。有點類似copy+shell+刪除copy的指令碼的這樣一個綜合的功能。

事前準備

為了更好地確認其功能,在ansible的控制節點和物件節點上的同樣目錄放置同樣名稱內容不同的檔案,確認其

  • >能否正常動作
  • >動作後是否能保證物件節點不受影響
[root@host31 ~]# /tmp/hello.sh
this is test from host31
[root@host31 ~]#
[root@host31 ~]# ssh host32 /tmp/hello.sh 
hello world ->同樣名稱 內容不同 [root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

使用script模組到物件節點上執行本地指令碼

[root@host31 ~]# ansible host32 -m script -a /tmp/hello.sh
host32 | SUCCESS => {
    "changed": true,
    "rc": 0,
    "stderr": "",
    "stdout": "this is test from host32\r\n",
    "stdout_lines"
: [ "this is test from host32" ->執行結果 ] } [root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

執行後確認

[root@host31 ~]# /tmp/hello.sh
this is test from host31
[root@host31 ~]# ssh host32 /tmp/hello.sh
hello world  ->未受影響
[root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5

再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!希望你也加入到我們人工智慧的隊伍中來!http://www.captainbed.net