初識ansible

概述

有誰知道ansible是怎麼讀的html

什麼是ansible

簡單的介紹一下這個東西,首先這個東西是用python寫的python

說一下個人環境

個人是四臺虛擬機,centos系統,而後的話是安裝了k8s的分別是shell

  • k8s-master
  • k8s-slave1
  • k8s-slave2
  • k8s-slave3
  • k8s-slave4

可是這個都無論,咱們主要是用來作ansible的實驗,還有若是文章中沒有說明,那麼一切操做都是在k8s-master節點上操做express

安裝

安裝直接使用包管理器安裝就行了vim

yum install epel-releasecentos

yum install ansiblebash

給機器添加祕鑰

首先在k8s-master節點生成祕鑰app

ssh-keygen -t rsadom

以後一路回車ssh

以後把祕鑰導入到每一臺機器中

ssh-copy-id root@192.168.1.151

ssh-copy-id root@192.168.1.156

ssh-copy-id root@192.168.1.148

ssh-copy-id root@192.168.1.139

配置ansible

下面有幾個配置文件要注意 一下

首先是

vim /etc/ansible/hosts

裏面定義的是集羣中的主機,好比個人

[k8s-server]
192.168.1.151
192.168.1.139
192.168.1.148
192.168.1.156

[k8s-master]
192.168.1.139

[k8s-slave]
192.168.1.148
192.168.1.156
192.168.1.151

上面這樣是一組主機,若是我要在這一組主機裏面去執行一個命令以下所示

[root@bboysoul-k8s-master ~]# ansible k8s-server -m shell -a "hostname"
192.168.1.151 | SUCCESS | rc=0 >>
bboysoul-k8s-slave1

192.168.1.156 | SUCCESS | rc=0 >>
bboysoul-k8s-slave3

192.168.1.148 | SUCCESS | rc=0 >>
bboysoul-k8s-slave2

192.168.1.139 | SUCCESS | rc=0 >>
bboysoul-k8s-master

k8s-server表示在這個組主機裏面執行命令,-m表示要使用的模塊,-a就是模塊裏面的參數

又以下面這樣

[root@bboysoul-k8s-master ~]# ansible k8s-master -m shell -a "hostname"
192.168.1.139 | SUCCESS | rc=0 >>
bboysoul-k8s-master

或者你想要在全部主機下執行這個命令

[root@bboysoul-k8s-master ~]# ansible all -m shell -a "hostname"
192.168.1.139 | SUCCESS | rc=0 >>
bboysoul-k8s-master

192.168.1.151 | SUCCESS | rc=0 >>
bboysoul-k8s-slave1

192.168.1.148 | SUCCESS | rc=0 >>
bboysoul-k8s-slave2

192.168.1.156 | SUCCESS | rc=0 >>
bboysoul-k8s-slave3

可能你以爲ansible執行某些命令會很慢,因此你能夠加上-f來fork出多個子進程來執行,可是要值得注意的是若是你執行的是一些簡單的命令就不要加了,由於fork進程也是須要時間的

ansible中的模塊

ansible中有不少模塊

咱們能夠使用

ansible-doc -l

來查看ansible中包含的一些模塊

固然咱們能夠這樣去搜索模塊

ansible-doc -l |grep copy

asnible-doc這個命令是用來獲取各個模塊的幫助信息的,好比我要查看copy模塊的幫助信息

ansible-doc -s copy

ansible的一些經常使用模塊

  • copy

這個模塊就是用來把本地的文件分發到遠程主機上的,好比

首先咱們先創建一個目錄

ansible all -m shell -a "mkdir /root/bboysoul"

以後咱們在本地下載一個小文件

wget http://mirrors.ustc.edu.cn/alpine/v3.8/releases/x86_64/alpine-standard-3.8.0_rc8-x86_64.iso

以後使用copy模塊分發

[root@bboysoul-k8s-master ~]# time ansible all -m copy -a "src=/root/alpine-standard-3.8.0_rc8-x86_64.iso dest=/root/bboysoul/alpine.iso"
192.168.1.139 | SUCCESS => {
    "changed": true, 
    "checksum": "01bb2a8206073ecd789367405854765236456737", 
    "dest": "/root/bboysoul/alpine.iso", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "640c9ccc23034a8a3237f5ca920cf339", 
    "mode": "0644", 
    "owner": "root", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 109051904, 
    "src": "/root/.ansible/tmp/ansible-tmp-1531285839.13-230038764878103/source", 
    "state": "file", 
    "uid": 0
}
192.168.1.151 | SUCCESS => {
    "changed": true, 
    "checksum": "01bb2a8206073ecd789367405854765236456737", 
    "dest": "/root/bboysoul/alpine.iso", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "640c9ccc23034a8a3237f5ca920cf339", 
    "mode": "0644", 
    "owner": "root", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 109051904, 
    "src": "/root/.ansible/tmp/ansible-tmp-1531285839.14-272099530710321/source", 
    "state": "file", 
    "uid": 0
}
192.168.1.156 | SUCCESS => {
    "changed": true, 
    "checksum": "01bb2a8206073ecd789367405854765236456737", 
    "dest": "/root/bboysoul/alpine.iso", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "640c9ccc23034a8a3237f5ca920cf339", 
    "mode": "0644", 
    "owner": "root", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 109051904, 
    "src": "/root/.ansible/tmp/ansible-tmp-1531285839.14-236085238208838/source", 
    "state": "file", 
    "uid": 0
}
192.168.1.148 | SUCCESS => {
    "changed": true, 
    "checksum": "01bb2a8206073ecd789367405854765236456737", 
    "dest": "/root/bboysoul/alpine.iso", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "640c9ccc23034a8a3237f5ca920cf339", 
    "mode": "0644", 
    "owner": "root", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 109051904, 
    "src": "/root/.ansible/tmp/ansible-tmp-1531285839.12-36460981766787/source", 
    "state": "file", 
    "uid": 0
}

real	0m17.358s
user	0m1.401s
sys	0m0.516s

爲了計算時間我使用了time命令

關於這個模塊還要說的是,src= 路徑後面帶/ 表示帶裏面的全部內容複製到目標目錄下,不帶/是目錄遞歸複製過去

  • shell

這個很少解釋了,就是執行shell命令的

  • cron

這個模塊是用來建立計劃任務的

好比建立一個每1分鐘ping一次百度的計劃任務

以前是沒有的

[root@bboysoul-k8s-master ~]# ansible all -m shell -a "crontab -l"
192.168.1.151 | FAILED | rc=1 >>
no crontab for rootnon-zero return code

192.168.1.148 | FAILED | rc=1 >>
no crontab for rootnon-zero return code

192.168.1.156 | FAILED | rc=1 >>
no crontab for rootnon-zero return code

192.168.1.139 | FAILED | rc=1 >>
no crontab for rootnon-zero return code

建立任務

ansible all -m cron -a "minute=*/1 job='ping baidu.com' name=ping"

以後查看任務

[root@bboysoul-k8s-master ~]# ansible all -m shell -a "crontab -l"
192.168.1.151 | SUCCESS | rc=0 >>
#Ansible: ping
*/1 * * * * ping baidu.com

192.168.1.148 | SUCCESS | rc=0 >>
#Ansible: ping
*/1 * * * * ping baidu.com

192.168.1.156 | SUCCESS | rc=0 >>
#Ansible: ping
*/1 * * * * ping baidu.com

192.168.1.139 | SUCCESS | rc=0 >>
#Ansible: ping
*/1 * * * * ping baidu.com
  • ** script**

這個就是把本地的腳本上傳到遠端去執行

首先新建一個腳本

[root@bboysoul-k8s-master ~]# cat test.sh
#!/bin/bash
echo "ansible test ok"

以後使用這個模塊執行

ansible all -m script -a "./test.sh"

關於模塊的總結

說真的模塊太多了,不可能每一個都知道都會使用的,若是你不會那麼

ansible-doc -s 模塊名

關於playbook

前面廢話說完了,下面進入正題playbook,若是說ansible的精髓是什麼那就是playbook了

咱們使用一個實例去入門這個playbook

就是使用playbook去安裝nmap

首先新建一個文件

vim playbook.yml

以後寫入

- hosts: all
  remote_user: root
  tasks: 
    - name: install nmap
      yum: name=nmap state=latest

    - name: install vim
      yum: name=vim state=latest

    - name: install whois
      yum: name=whois state=latest

    - name: whois bboysoul
      shell: whois bboysoul.com

檢查一下語法

ansible-playbook --syntax-check playbook.yml

查看一下涉及到的主機

[root@bboysoul-k8s-master ~]# ansible-playbook --list-hosts playbook.yml 

playbook: playbook.yml

  play #1 (all): all	TAGS: []
    pattern: [u'all']
    hosts (4):
      192.168.1.139
      192.168.1.151
      192.168.1.148
      192.168.1.156

以後查看一下可能會發生的改變

ansible-playbook --check playbook.yml

[root@bboysoul-k8s-master ~]# ansible-playbook --check playbook.yml 

PLAY [all] ********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [192.168.1.148]
ok: [192.168.1.151]
ok: [192.168.1.156]
ok: [192.168.1.139]

TASK [install nmap] ***********************************************************************************************************************************************************************************************
changed: [192.168.1.156]
changed: [192.168.1.151]
changed: [192.168.1.148]
changed: [192.168.1.139]

TASK [install vim] ************************************************************************************************************************************************************************************************
changed: [192.168.1.156]
ok: [192.168.1.139]
changed: [192.168.1.148]
changed: [192.168.1.151]

TASK [install whois] **********************************************************************************************************************************************************************************************
changed: [192.168.1.156]
changed: [192.168.1.148]
changed: [192.168.1.151]
changed: [192.168.1.139]

TASK [whois bboysoul] *********************************************************************************************************************************************************************************************
skipping: [192.168.1.156]
skipping: [192.168.1.151]
skipping: [192.168.1.148]
skipping: [192.168.1.139]

PLAY RECAP ********************************************************************************************************************************************************************************************************
192.168.1.139              : ok=4    changed=2    unreachable=0    failed=0   
192.168.1.148              : ok=4    changed=3    unreachable=0    failed=0   
192.168.1.151              : ok=4    changed=3    unreachable=0    failed=0   
192.168.1.156              : ok=4    changed=3    unreachable=0    failed=0

注意,這個時候其實命令是沒有被執行的,只是檢查一下命令是否是正確而已

最後執行

[root@bboysoul-k8s-master ~]# ansible-playbook playbook.yml 

PLAY [all] ********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [192.168.1.156]
ok: [192.168.1.148]
ok: [192.168.1.151]
ok: [192.168.1.139]

TASK [install nmap] ***********************************************************************************************************************************************************************************************
changed: [192.168.1.156]
changed: [192.168.1.151]
changed: [192.168.1.148]
changed: [192.168.1.139]

TASK [install vim] ************************************************************************************************************************************************************************************************
changed: [192.168.1.156]
ok: [192.168.1.139]
changed: [192.168.1.151]
changed: [192.168.1.148]

TASK [install whois] **********************************************************************************************************************************************************************************************
changed: [192.168.1.156]
changed: [192.168.1.148]
changed: [192.168.1.151]
changed: [192.168.1.139]

TASK [whois bboysoul] *********************************************************************************************************************************************************************************************
fatal: [192.168.1.151]: FAILED! => {"changed": true, "cmd": "whois bboysoul.com", "delta": "0:00:00.436371", "end": "2018-07-11 16:24:41.250469", "msg": "non-zero return code", "rc": 1, "start": "2018-07-11 16:24:40.814098", "stderr": "", "stderr_lines": [], "stdout": "   Domain Name: BBOYSOUL.COM\n   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN\n   Registrar WHOIS Server: grs-whois.hichina.com\n   Registrar URL: http://www.net.cn\n   Updated Date: 2018-04-24T01:30:46Z\n   Creation Date: 2017-08-16T18:06:53Z\n   Registry Expiry Date: 2018-08-16T18:06:53Z\n   Registrar: HiChina Zhicheng Technology Ltd.\n   Registrar IANA ID: 420\n   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com\n   Registrar Abuse Contact Phone: +86.95187\n   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited\n   Name Server: DNS17.HICHINA.COM\n   Name Server: DNS18.HICHINA.COM\n   DNSSEC: unsigned\n   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/\n>>> Last update of whois database: 2018-07-11T08:24:27Z <<<\n\nFor more information on Whois status codes, please visit https://icann.org/epp\n\nNOTICE: The expiration date displayed in this record is the date the\nregistrar's sponsorship of the domain name registration in the registry is\ncurrently set to expire. This date does not necessarily reflect the expiration\ndate of the domain name registrant's agreement with the sponsoring\nregistrar.  Users may consult the sponsoring registrar's Whois database to\nview the registrar's reported date of expiration for this registration.\n\nTERMS OF USE: You are not authorized to access or query our Whois\ndatabase through the use of electronic processes that are high-volume and\nautomated except as reasonably necessary to register domain names or\nmodify existing registrations; the Data in VeriSign Global Registry\nServices' (\"VeriSign\") Whois database is provided by VeriSign for\ninformation purposes only, and to assist persons in obtaining information\nabout or related to a domain name registration record. VeriSign does not\nguarantee its accuracy. By submitting a Whois query, you agree to abide\nby the following terms of use: You agree that you may use this Data only\nfor lawful purposes and that under no circumstances will you use this Data\nto: (1) allow, enable, or otherwise support the transmission of mass\nunsolicited, commercial advertising or solicitations via e-mail, telephone,\nor facsimile; or (2) enable high volume, automated, electronic processes\nthat apply to VeriSign (or its computer systems). The compilation,\nrepackaging, dissemination or other use of this Data is expressly\nprohibited without the prior written consent of VeriSign. You agree not to\nuse electronic processes that are automated and high-volume to access or\nquery the Whois database except as reasonably necessary to register\ndomain names or modify existing registrations. VeriSign reserves the right\nto restrict your access to the Whois database in its sole discretion to ensure\noperational stability.  VeriSign may restrict or terminate your access to the\nWhois database for failure to abide by these terms of use. VeriSign\nreserves the right to modify these terms at any time.\n\nThe Registry database contains ONLY .COM, .NET, .EDU domains and\nRegistrars.", "stdout_lines": ["   Domain Name: BBOYSOUL.COM", "   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN", "   Registrar WHOIS Server: grs-whois.hichina.com", "   Registrar URL: http://www.net.cn", "   Updated Date: 2018-04-24T01:30:46Z", "   Creation Date: 2017-08-16T18:06:53Z", "   Registry Expiry Date: 2018-08-16T18:06:53Z", "   Registrar: HiChina Zhicheng Technology Ltd.", "   Registrar IANA ID: 420", "   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com", "   Registrar Abuse Contact Phone: +86.95187", "   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited", "   Name Server: DNS17.HICHINA.COM", "   Name Server: DNS18.HICHINA.COM", "   DNSSEC: unsigned", "   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/", ">>> Last update of whois database: 2018-07-11T08:24:27Z <<<", "", "For more information on Whois status codes, please visit https://icann.org/epp", "", "NOTICE: The expiration date displayed in this record is the date the", "registrar's sponsorship of the domain name registration in the registry is", "currently set to expire. This date does not necessarily reflect the expiration", "date of the domain name registrant's agreement with the sponsoring", "registrar.  Users may consult the sponsoring registrar's Whois database to", "view the registrar's reported date of expiration for this registration.", "", "TERMS OF USE: You are not authorized to access or query our Whois", "database through the use of electronic processes that are high-volume and", "automated except as reasonably necessary to register domain names or", "modify existing registrations; the Data in VeriSign Global Registry", "Services' (\"VeriSign\") Whois database is provided by VeriSign for", "information purposes only, and to assist persons in obtaining information", "about or related to a domain name registration record. VeriSign does not", "guarantee its accuracy. By submitting a Whois query, you agree to abide", "by the following terms of use: You agree that you may use this Data only", "for lawful purposes and that under no circumstances will you use this Data", "to: (1) allow, enable, or otherwise support the transmission of mass", "unsolicited, commercial advertising or solicitations via e-mail, telephone,", "or facsimile; or (2) enable high volume, automated, electronic processes", "that apply to VeriSign (or its computer systems). The compilation,", "repackaging, dissemination or other use of this Data is expressly", "prohibited without the prior written consent of VeriSign. You agree not to", "use electronic processes that are automated and high-volume to access or", "query the Whois database except as reasonably necessary to register", "domain names or modify existing registrations. VeriSign reserves the right", "to restrict your access to the Whois database in its sole discretion to ensure", "operational stability.  VeriSign may restrict or terminate your access to the", "Whois database for failure to abide by these terms of use. VeriSign", "reserves the right to modify these terms at any time.", "", "The Registry database contains ONLY .COM, .NET, .EDU domains and", "Registrars."]}
fatal: [192.168.1.156]: FAILED! => {"changed": true, "cmd": "whois bboysoul.com", "delta": "0:00:00.695995", "end": "2018-07-11 16:24:41.399184", "msg": "non-zero return code", "rc": 1, "start": "2018-07-11 16:24:40.703189", "stderr": "", "stderr_lines": [], "stdout": "   Domain Name: BBOYSOUL.COM\n   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN\n   Registrar WHOIS Server: grs-whois.hichina.com\n   Registrar URL: http://www.net.cn\n   Updated Date: 2018-04-24T01:30:46Z\n   Creation Date: 2017-08-16T18:06:53Z\n   Registry Expiry Date: 2018-08-16T18:06:53Z\n   Registrar: HiChina Zhicheng Technology Ltd.\n   Registrar IANA ID: 420\n   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com\n   Registrar Abuse Contact Phone: +86.95187\n   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited\n   Name Server: DNS17.HICHINA.COM\n   Name Server: DNS18.HICHINA.COM\n   DNSSEC: unsigned\n   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/\n>>> Last update of whois database: 2018-07-11T08:24:27Z <<<\n\nFor more information on Whois status codes, please visit https://icann.org/epp\n\nNOTICE: The expiration date displayed in this record is the date the\nregistrar's sponsorship of the domain name registration in the registry is\ncurrently set to expire. This date does not necessarily reflect the expiration\ndate of the domain name registrant's agreement with the sponsoring\nregistrar.  Users may consult the sponsoring registrar's Whois database to\nview the registrar's reported date of expiration for this registration.\n\nTERMS OF USE: You are not authorized to access or query our Whois\ndatabase through the use of electronic processes that are high-volume and\nautomated except as reasonably necessary to register domain names or\nmodify existing registrations; the Data in VeriSign Global Registry\nServices' (\"VeriSign\") Whois database is provided by VeriSign for\ninformation purposes only, and to assist persons in obtaining information\nabout or related to a domain name registration record. VeriSign does not\nguarantee its accuracy. By submitting a Whois query, you agree to abide\nby the following terms of use: You agree that you may use this Data only\nfor lawful purposes and that under no circumstances will you use this Data\nto: (1) allow, enable, or otherwise support the transmission of mass\nunsolicited, commercial advertising or solicitations via e-mail, telephone,\nor facsimile; or (2) enable high volume, automated, electronic processes\nthat apply to VeriSign (or its computer systems). The compilation,\nrepackaging, dissemination or other use of this Data is expressly\nprohibited without the prior written consent of VeriSign. You agree not to\nuse electronic processes that are automated and high-volume to access or\nquery the Whois database except as reasonably necessary to register\ndomain names or modify existing registrations. VeriSign reserves the right\nto restrict your access to the Whois database in its sole discretion to ensure\noperational stability.  VeriSign may restrict or terminate your access to the\nWhois database for failure to abide by these terms of use. VeriSign\nreserves the right to modify these terms at any time.\n\nThe Registry database contains ONLY .COM, .NET, .EDU domains and\nRegistrars.", "stdout_lines": ["   Domain Name: BBOYSOUL.COM", "   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN", "   Registrar WHOIS Server: grs-whois.hichina.com", "   Registrar URL: http://www.net.cn", "   Updated Date: 2018-04-24T01:30:46Z", "   Creation Date: 2017-08-16T18:06:53Z", "   Registry Expiry Date: 2018-08-16T18:06:53Z", "   Registrar: HiChina Zhicheng Technology Ltd.", "   Registrar IANA ID: 420", "   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com", "   Registrar Abuse Contact Phone: +86.95187", "   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited", "   Name Server: DNS17.HICHINA.COM", "   Name Server: DNS18.HICHINA.COM", "   DNSSEC: unsigned", "   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/", ">>> Last update of whois database: 2018-07-11T08:24:27Z <<<", "", "For more information on Whois status codes, please visit https://icann.org/epp", "", "NOTICE: The expiration date displayed in this record is the date the", "registrar's sponsorship of the domain name registration in the registry is", "currently set to expire. This date does not necessarily reflect the expiration", "date of the domain name registrant's agreement with the sponsoring", "registrar.  Users may consult the sponsoring registrar's Whois database to", "view the registrar's reported date of expiration for this registration.", "", "TERMS OF USE: You are not authorized to access or query our Whois", "database through the use of electronic processes that are high-volume and", "automated except as reasonably necessary to register domain names or", "modify existing registrations; the Data in VeriSign Global Registry", "Services' (\"VeriSign\") Whois database is provided by VeriSign for", "information purposes only, and to assist persons in obtaining information", "about or related to a domain name registration record. VeriSign does not", "guarantee its accuracy. By submitting a Whois query, you agree to abide", "by the following terms of use: You agree that you may use this Data only", "for lawful purposes and that under no circumstances will you use this Data", "to: (1) allow, enable, or otherwise support the transmission of mass", "unsolicited, commercial advertising or solicitations via e-mail, telephone,", "or facsimile; or (2) enable high volume, automated, electronic processes", "that apply to VeriSign (or its computer systems). The compilation,", "repackaging, dissemination or other use of this Data is expressly", "prohibited without the prior written consent of VeriSign. You agree not to", "use electronic processes that are automated and high-volume to access or", "query the Whois database except as reasonably necessary to register", "domain names or modify existing registrations. VeriSign reserves the right", "to restrict your access to the Whois database in its sole discretion to ensure", "operational stability.  VeriSign may restrict or terminate your access to the", "Whois database for failure to abide by these terms of use. VeriSign", "reserves the right to modify these terms at any time.", "", "The Registry database contains ONLY .COM, .NET, .EDU domains and", "Registrars."]}
fatal: [192.168.1.148]: FAILED! => {"changed": true, "cmd": "whois bboysoul.com", "delta": "0:00:00.691615", "end": "2018-07-11 16:24:41.729534", "msg": "non-zero return code", "rc": 1, "start": "2018-07-11 16:24:41.037919", "stderr": "", "stderr_lines": [], "stdout": "   Domain Name: BBOYSOUL.COM\n   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN\n   Registrar WHOIS Server: grs-whois.hichina.com\n   Registrar URL: http://www.net.cn\n   Updated Date: 2018-04-24T01:30:46Z\n   Creation Date: 2017-08-16T18:06:53Z\n   Registry Expiry Date: 2018-08-16T18:06:53Z\n   Registrar: HiChina Zhicheng Technology Ltd.\n   Registrar IANA ID: 420\n   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com\n   Registrar Abuse Contact Phone: +86.95187\n   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited\n   Name Server: DNS17.HICHINA.COM\n   Name Server: DNS18.HICHINA.COM\n   DNSSEC: unsigned\n   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/\n>>> Last update of whois database: 2018-07-11T08:24:27Z <<<\n\nFor more information on Whois status codes, please visit https://icann.org/epp\n\nNOTICE: The expiration date displayed in this record is the date the\nregistrar's sponsorship of the domain name registration in the registry is\ncurrently set to expire. This date does not necessarily reflect the expiration\ndate of the domain name registrant's agreement with the sponsoring\nregistrar.  Users may consult the sponsoring registrar's Whois database to\nview the registrar's reported date of expiration for this registration.\n\nTERMS OF USE: You are not authorized to access or query our Whois\ndatabase through the use of electronic processes that are high-volume and\nautomated except as reasonably necessary to register domain names or\nmodify existing registrations; the Data in VeriSign Global Registry\nServices' (\"VeriSign\") Whois database is provided by VeriSign for\ninformation purposes only, and to assist persons in obtaining information\nabout or related to a domain name registration record. VeriSign does not\nguarantee its accuracy. By submitting a Whois query, you agree to abide\nby the following terms of use: You agree that you may use this Data only\nfor lawful purposes and that under no circumstances will you use this Data\nto: (1) allow, enable, or otherwise support the transmission of mass\nunsolicited, commercial advertising or solicitations via e-mail, telephone,\nor facsimile; or (2) enable high volume, automated, electronic processes\nthat apply to VeriSign (or its computer systems). The compilation,\nrepackaging, dissemination or other use of this Data is expressly\nprohibited without the prior written consent of VeriSign. You agree not to\nuse electronic processes that are automated and high-volume to access or\nquery the Whois database except as reasonably necessary to register\ndomain names or modify existing registrations. VeriSign reserves the right\nto restrict your access to the Whois database in its sole discretion to ensure\noperational stability.  VeriSign may restrict or terminate your access to the\nWhois database for failure to abide by these terms of use. VeriSign\nreserves the right to modify these terms at any time.\n\nThe Registry database contains ONLY .COM, .NET, .EDU domains and\nRegistrars.", "stdout_lines": ["   Domain Name: BBOYSOUL.COM", "   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN", "   Registrar WHOIS Server: grs-whois.hichina.com", "   Registrar URL: http://www.net.cn", "   Updated Date: 2018-04-24T01:30:46Z", "   Creation Date: 2017-08-16T18:06:53Z", "   Registry Expiry Date: 2018-08-16T18:06:53Z", "   Registrar: HiChina Zhicheng Technology Ltd.", "   Registrar IANA ID: 420", "   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com", "   Registrar Abuse Contact Phone: +86.95187", "   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited", "   Name Server: DNS17.HICHINA.COM", "   Name Server: DNS18.HICHINA.COM", "   DNSSEC: unsigned", "   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/", ">>> Last update of whois database: 2018-07-11T08:24:27Z <<<", "", "For more information on Whois status codes, please visit https://icann.org/epp", "", "NOTICE: The expiration date displayed in this record is the date the", "registrar's sponsorship of the domain name registration in the registry is", "currently set to expire. This date does not necessarily reflect the expiration", "date of the domain name registrant's agreement with the sponsoring", "registrar.  Users may consult the sponsoring registrar's Whois database to", "view the registrar's reported date of expiration for this registration.", "", "TERMS OF USE: You are not authorized to access or query our Whois", "database through the use of electronic processes that are high-volume and", "automated except as reasonably necessary to register domain names or", "modify existing registrations; the Data in VeriSign Global Registry", "Services' (\"VeriSign\") Whois database is provided by VeriSign for", "information purposes only, and to assist persons in obtaining information", "about or related to a domain name registration record. VeriSign does not", "guarantee its accuracy. By submitting a Whois query, you agree to abide", "by the following terms of use: You agree that you may use this Data only", "for lawful purposes and that under no circumstances will you use this Data", "to: (1) allow, enable, or otherwise support the transmission of mass", "unsolicited, commercial advertising or solicitations via e-mail, telephone,", "or facsimile; or (2) enable high volume, automated, electronic processes", "that apply to VeriSign (or its computer systems). The compilation,", "repackaging, dissemination or other use of this Data is expressly", "prohibited without the prior written consent of VeriSign. You agree not to", "use electronic processes that are automated and high-volume to access or", "query the Whois database except as reasonably necessary to register", "domain names or modify existing registrations. VeriSign reserves the right", "to restrict your access to the Whois database in its sole discretion to ensure", "operational stability.  VeriSign may restrict or terminate your access to the", "Whois database for failure to abide by these terms of use. VeriSign", "reserves the right to modify these terms at any time.", "", "The Registry database contains ONLY .COM, .NET, .EDU domains and", "Registrars."]}
fatal: [192.168.1.139]: FAILED! => {"changed": true, "cmd": "whois bboysoul.com", "delta": "0:00:01.107660", "end": "2018-07-11 16:24:41.693555", "msg": "non-zero return code", "rc": 1, "start": "2018-07-11 16:24:40.585895", "stderr": "", "stderr_lines": [], "stdout": "   Domain Name: BBOYSOUL.COM\n   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN\n   Registrar WHOIS Server: grs-whois.hichina.com\n   Registrar URL: http://www.net.cn\n   Updated Date: 2018-04-24T01:30:46Z\n   Creation Date: 2017-08-16T18:06:53Z\n   Registry Expiry Date: 2018-08-16T18:06:53Z\n   Registrar: HiChina Zhicheng Technology Ltd.\n   Registrar IANA ID: 420\n   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com\n   Registrar Abuse Contact Phone: +86.95187\n   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited\n   Name Server: DNS17.HICHINA.COM\n   Name Server: DNS18.HICHINA.COM\n   DNSSEC: unsigned\n   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/\n>>> Last update of whois database: 2018-07-11T08:24:27Z <<<\n\nFor more information on Whois status codes, please visit https://icann.org/epp\n\nNOTICE: The expiration date displayed in this record is the date the\nregistrar's sponsorship of the domain name registration in the registry is\ncurrently set to expire. This date does not necessarily reflect the expiration\ndate of the domain name registrant's agreement with the sponsoring\nregistrar.  Users may consult the sponsoring registrar's Whois database to\nview the registrar's reported date of expiration for this registration.\n\nTERMS OF USE: You are not authorized to access or query our Whois\ndatabase through the use of electronic processes that are high-volume and\nautomated except as reasonably necessary to register domain names or\nmodify existing registrations; the Data in VeriSign Global Registry\nServices' (\"VeriSign\") Whois database is provided by VeriSign for\ninformation purposes only, and to assist persons in obtaining information\nabout or related to a domain name registration record. VeriSign does not\nguarantee its accuracy. By submitting a Whois query, you agree to abide\nby the following terms of use: You agree that you may use this Data only\nfor lawful purposes and that under no circumstances will you use this Data\nto: (1) allow, enable, or otherwise support the transmission of mass\nunsolicited, commercial advertising or solicitations via e-mail, telephone,\nor facsimile; or (2) enable high volume, automated, electronic processes\nthat apply to VeriSign (or its computer systems). The compilation,\nrepackaging, dissemination or other use of this Data is expressly\nprohibited without the prior written consent of VeriSign. You agree not to\nuse electronic processes that are automated and high-volume to access or\nquery the Whois database except as reasonably necessary to register\ndomain names or modify existing registrations. VeriSign reserves the right\nto restrict your access to the Whois database in its sole discretion to ensure\noperational stability.  VeriSign may restrict or terminate your access to the\nWhois database for failure to abide by these terms of use. VeriSign\nreserves the right to modify these terms at any time.\n\nThe Registry database contains ONLY .COM, .NET, .EDU domains and\nRegistrars.", "stdout_lines": ["   Domain Name: BBOYSOUL.COM", "   Registry Domain ID: 2154086731_DOMAIN_COM-VRSN", "   Registrar WHOIS Server: grs-whois.hichina.com", "   Registrar URL: http://www.net.cn", "   Updated Date: 2018-04-24T01:30:46Z", "   Creation Date: 2017-08-16T18:06:53Z", "   Registry Expiry Date: 2018-08-16T18:06:53Z", "   Registrar: HiChina Zhicheng Technology Ltd.", "   Registrar IANA ID: 420", "   Registrar Abuse Contact Email: DomainAbuse@service.aliyun.com", "   Registrar Abuse Contact Phone: +86.95187", "   Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited", "   Name Server: DNS17.HICHINA.COM", "   Name Server: DNS18.HICHINA.COM", "   DNSSEC: unsigned", "   URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/", ">>> Last update of whois database: 2018-07-11T08:24:27Z <<<", "", "For more information on Whois status codes, please visit https://icann.org/epp", "", "NOTICE: The expiration date displayed in this record is the date the", "registrar's sponsorship of the domain name registration in the registry is", "currently set to expire. This date does not necessarily reflect the expiration", "date of the domain name registrant's agreement with the sponsoring", "registrar.  Users may consult the sponsoring registrar's Whois database to", "view the registrar's reported date of expiration for this registration.", "", "TERMS OF USE: You are not authorized to access or query our Whois", "database through the use of electronic processes that are high-volume and", "automated except as reasonably necessary to register domain names or", "modify existing registrations; the Data in VeriSign Global Registry", "Services' (\"VeriSign\") Whois database is provided by VeriSign for", "information purposes only, and to assist persons in obtaining information", "about or related to a domain name registration record. VeriSign does not", "guarantee its accuracy. By submitting a Whois query, you agree to abide", "by the following terms of use: You agree that you may use this Data only", "for lawful purposes and that under no circumstances will you use this Data", "to: (1) allow, enable, or otherwise support the transmission of mass", "unsolicited, commercial advertising or solicitations via e-mail, telephone,", "or facsimile; or (2) enable high volume, automated, electronic processes", "that apply to VeriSign (or its computer systems). The compilation,", "repackaging, dissemination or other use of this Data is expressly", "prohibited without the prior written consent of VeriSign. You agree not to", "use electronic processes that are automated and high-volume to access or", "query the Whois database except as reasonably necessary to register", "domain names or modify existing registrations. VeriSign reserves the right", "to restrict your access to the Whois database in its sole discretion to ensure", "operational stability.  VeriSign may restrict or terminate your access to the", "Whois database for failure to abide by these terms of use. VeriSign", "reserves the right to modify these terms at any time.", "", "The Registry database contains ONLY .COM, .NET, .EDU domains and", "Registrars."]}
	to retry, use: --limit @/root/playbook.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
192.168.1.139              : ok=4    changed=2    unreachable=0    failed=1   
192.168.1.148              : ok=4    changed=3    unreachable=0    failed=1   
192.168.1.151              : ok=4    changed=3    unreachable=0    failed=1   
192.168.1.156              : ok=4    changed=3    unreachable=0    failed=1

沒錯,你看到有一步是出錯的,其實並無出錯,你能夠看到whois信息仍是出來的

關於playbook,詳細的能夠看文檔

http://ansible-tran.readthedocs.io/en/latest/docs/playbooks_intro.html

說真的,有了ansible,媽媽不再用擔憂我要在不一樣的主機上執行相同的命令,就連ddos也變得方便起來

歡迎關注Bboysoul的博客www.bboysoul.com Have Fun

相關文章
相關標籤/搜索