Ansible---命令行應(yīng)用

ansible遠程管理工具;

時間同步
名字解析

1成榜、安裝ansible;
Yum install ansible
=======================================================================================================================================================================
 Package                                                     Arch                           Version                                  Repository                   Size
=======================================================================================================================================================================
Installing:
 ansible                                                     noarch                         2.2.1.0-1.el7                            web                         4.6 M
Installing for dependencies:
 PyYAML                                                      x86_64                         3.10-11.el7                              dev                         153 k
 libtomcrypt                                                 x86_64                         1.17-23.el7                              web                         224 k
 libtommath                                                  x86_64                         0.42.0-4.el7                             web                          35 k
 libyaml                                                     x86_64                         0.1.4-11.el7_0                           dev                          55 k
 python-babel                                                noarch                         0.9.6-8.el7                              dev                         1.4 M
 python-backports                                            x86_64                         1.0-8.el7                                dev                         5.8 k
 python-backports-ssl_match_hostname                         noarch                         3.4.0.2-4.el7                            dev                          12 k
 python-httplib2                                             noarch                         0.7.7-3.el7                              web                          70 k
 python-jinja2                                               noarch                         2.7.2-2.el7                              dev                         515 k
 python-keyczar                                              noarch                         0.71c-2.el7                              web                         218 k
 python-markupsafe                                           x86_64                         0.11-10.el7                              dev                          25 k
 python-setuptools                                           noarch                         0.9.8-4.el7                              dev                         396 k
 python-six                                                  noarch                         1.9.0-2.el7                              dev                          29 k
 python2-crypto                                              x86_64                         2.6.1-13.el7                             web                         476 k
 python2-ecdsa                                               noarch                         0.13-4.el7                               web                          83 k
 python2-paramiko                                            noarch                         1.16.1-2.el7                             web                         258 k
 python2-pyasn1                                              noarch                         0.1.9-7.el7                              dev                         100 k
 sshpass                                                     x86_64                         1.06-1.el7                               web                          21 k

Transaction Summary
=======================================================================================================================================================================
Install  1 Package (+18 Dependent packages)


/etc/ansible     ---------------配置文件所在目錄位置
/etc/ansible/ansible.cfg ---主配置文件
/etc/ansible/hosts----------主機清單
/etc/ansible/roles-----------角色目錄
/usr/bin/ansible-------------主程序
/usr/bin/ansible-console
/usr/bin/ansible-doc
/usr/bin/ansible-galaxy
/usr/bin/ansible-playbook
/usr/bin/ansible-pull--------從客戶端拉取工具
/usr/bin/ansible-vault


/etc/ansible/ansible.cfg ---主配置文件斟珊,關(guān)于自身的配置文件达罗;

Ansible 一兩種方式完成管理,命令行或劇本方式完成

命令行躯喇;
Ansible host-pattern  options
Ansible -a  -m   傳遞模塊參數(shù)
Ansible -C          測試執(zhí)行
Ansible -f        默認管控5個
ansible  -I       指明主機清單
Ansible  -l          列出主機
Ansible -t       將日志記錄與指定的位置文件中

連接命令選項咏窿;

Ansible -c        指定以什么方式連接目標主機
Ansible -u        指明目標主機使用連接時的用戶碌秸;默認為none;

權(quán)限升級方式;Privilege escalation options;

ansible     -s      切換sudo操作艳悔;
Ansible    -U      su到某個用戶進行操作急凰;
Ansible    -b      轉(zhuǎn)變至某個用戶操作;


秘鑰認證猜年;
#ssh-keygen -t rsa -P ""
將生成的蜜鑰發(fā)送另兩臺主機抡锈;
#ssh-copy-id -I ~/.ssh/id_rsa.pub root@172.16.88.2
#ssh-copy-id -I ~/.ssh/id_rsa.pub root@172.16.88.3

[root@localhost ~]#ssh-keygen -t rsa -P ""
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
2f:3d:fc:15:67:32:4d:89:59:6b:05:2c:73:bb:fe:51 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|             ..o.|
|            o * +|
|             * =.|
|              oo |
|        S     +.E|
|         +    .*.|
|        . =  ... |
|         . o .. .|
|            .  ..|
+-----------------+

[root@localhost ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.88.2
The authenticity of host '172.16.88.2 (172.16.88.2)' can't be established.
ECDSA key fingerprint is 75:9e:e0:a9:31:ce:cb:73:ed:8a:17:d6:9d:3d:6a:2b.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.16.88.2's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.16.88.2'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.88.1
The authenticity of host '172.16.88.1 (172.16.88.1)' can't be established.
ECDSA key fingerprint is ce:2d:bd:83:46:37:94:45:27:2d:65:b8:71:f3:32:93.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.16.88.1's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.16.88.1'"
and check to make sure that only the key(s) you wanted were added.

設(shè)置名字解析;
[root@localhost ~]#scp /etc/hosts root@172.16.88.2:/etc/hosts
The authenticity of host '172.16.88.2 (172.16.88.2)' can't be established.
ECDSA key fingerprint is 75:9e:e0:a9:31:ce:cb:73:ed:8a:17:d6:9d:3d:6a:2b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.88.2' (ECDSA) to the list of known hosts.
root@172.16.88.2's password: 
hosts                                                            
[root@localhost ~]#cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.88.1 node1.mageedu.com  node1
172.16.88.2 node2.mageedu.com  node2
172.16.88.3 node3.mageedu.com  node3
172.16.88.4 node4.mageedu.com  node4

定義管控的主機乔外,編輯配置文件床三;
Vim /etc/ansible/hosts
[Websrvs]
172.16.88.2
172.16.88.3
[dbsrvs]
172.16.88.3

命令行;
列出控制的主機杨幼;
[root@localhost ansible]#ansible all -m ping --list-hosts
  hosts (2):
    172.16.88.1
    172.16.88.2
探測目標主機是否可頻通勿璃;
[root@localhost ansible]#ansible all -m ping -C
172.16.88.1 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
172.16.88.2 | SUCCESS => {
    "changed": false, 
    "ping": "pong"

[root@localhost ansible]#ansible-doc --help
Usage: ansible-doc [options] [module...]

Options:
  -h, --help            show this help message and exit
  -l, --list            List available modules
  -M MODULE_PATH, --module-path=MODULE_PATH
                        specify path(s) to module library (default=None)
  -s, --snippet         Show playbook snippet for specified module(s)
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)
  --version             show program's version number and exit

Ansible-doc -a  顯示所有模塊文檔
Ansible-doc -l   列出所有可用模塊
Ansible-doc -M
Ansible-doc -s  顯示playbooks當中使用的選項;

    ? group模塊,查看定義組的選項补疑;
[root@localhost ansible]#ansible-doc -s group
- name: Add or remove groups
  action: group
      gid                    # Optional `GID' to set for the group.
      name=                  # Name of the group to manage.
      state                  # Whether the group should be present or not on the remote host.
      system                 # If `yes', indicates that the group created is a system group.
[root@localhost ansible]#

State---可以創(chuàng)建或刪除

Ansible all -m group -a "gid=1012 name=mygrp state=present system=no"

[root@localhost ~]#tail -1 /etc/group
mygrp:x:1012:
 
Ansible all -m group -a "gid=1012 name=mygrp state=absent system=no"


    ? user模塊歧沪,查看創(chuàng)建用戶選項;
#Ansible-doc -s 
Name= 
Comment---注釋信息
Expires------過期時間
Group-------基本組
Groups------附加組
Home-------家目錄
Password----密碼
Shell---------shell類型
State --------創(chuàng)建莲组,刪除 persent,absent
System ---------是否為系統(tǒng)用戶
Uid-----------用戶id
Move home----當創(chuàng)建家目錄是原有的文件是否移動過來诊胞,等于no時創(chuàng)建新的家目錄,原有的文件不會移動過來
Generate_ssh_key---創(chuàng)建用戶是自動生成一對蜜鑰锹杈,原來有蜜鑰不會覆蓋撵孤,重新創(chuàng)建一對蜜鑰

創(chuàng)建用戶,添加附加組
[root@localhost ansible]#ansible all -m user -a "uid=5000 name=testuser state=present system=no groups=mygrp shell=/bin/tcsh"
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "createhome": true, 
    "group": 5000, 
    "groups": "mygrp", 
    "home": "/home/testuser", 
    "name": "testuser", 
    "shell": "/bin/tcsh", 
    "state": "present", 
    "system": false, 
    "uid": 5000
}
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "createhome": true, 
    "group": 5000, 
    "groups": "mygrp", 
    "home": "/home/testuser", 
    "name": "testuser", 
    "shell": "/bin/tcsh", 
    "state": "present", 
    "system": false, 
    "uid": 5000
}

    ? copy模塊
[root@localhost ~]#ansible-doc -s copy
Ansible ----dest= 目標路徑竭望,遠程主機的絕對路徑
Ansible--------Src-----源可以相對邪码,也可以是絕對的,源文件以斜線結(jié)尾咬清、/ 將目錄中的內(nèi)容復(fù)制過去闭专,不帶斜線,將整個目錄遞歸復(fù)制過去旧烧。
Ansible-------Owner屬主
Ansible-------group屬組
Ansible----mode--------權(quán)限
Ansible------Remode src---從遠程復(fù)制到遠程
Ansible ------content ----指定內(nèi)容生成目標文件生成的內(nèi)容影钉,不用指定src源文件;

拷貝內(nèi)容到遠程主機掘剪;
[root@localhost ansible]#ansible all -m copy -a  " src=/etc/fstab dest=/tmp/fstab.ansibled mode=600 "  
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "checksum": "38e9d94be631342601af30347dca5d61ae09172c", 
    "dest": "/tmp/fstab.ansibled", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "b91107d726fc7502b6d74ffce58a6dd0", 
    "mode": "0600", 
    "owner": "root", 
    "secontext": "unconfined_u:object_r:admin_home_t:s0", 
    "size": 541, 
    "src": "/root/.ansible/tmp/ansible-tmp-1505840510.12-83854192085881/source", 
    "state": "file", 
    "uid": 0
}
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "checksum": "38e9d94be631342601af30347dca5d61ae09172c", 
    "dest": "/tmp/fstab.ansibled", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "b91107d726fc7502b6d74ffce58a6dd0", 
    "mode": "0600", 
    "owner": "root", 
    "secontext": "unconfined_u:object_r:admin_home_t:s0", 
    "size": 541, 
    "src": "/root/.ansible/tmp/ansible-tmp-1505840510.12-83768663591640/source", 
    "state": "file", 
    "uid": 0
}

Ansible all -m copy -a "src=/etc/pam.d/ dest=/tmp/"
Ansible all -m copy -a "src=/etc/pam.d dest=/tmp/"
兩種復(fù)制的區(qū)別在于平委,復(fù)制文件和復(fù)制目錄

給定內(nèi)容拷貝到遠程主機;
[root@localhost ansible]#ansible all -m copy -a "content='hi there\n' dest=/tmp/hi.txt" 
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "checksum": "56170f5429b35dea081bb659b884b475ca9329a9", 
    "dest": "/tmp/hi.txt", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "fd33e2e8ad3cb1bdd3ea8f5633fcf5c7", 
    "mode": "0644", 
    "owner": "root", 
    "secontext": "unconfined_u:object_r:admin_home_t:s0", 
    "size": 8, 
    "src": "/root/.ansible/tmp/ansible-tmp-1505841223.02-222568091857457/source", 
    "state": "file", 
    "uid": 0
}
將屬主夺谁,屬組改變?yōu)楝F(xiàn)有的testuser,mygrp
[root@localhost ansible]#ansible all -m copy -a "content='hi there\n' dest=/tmp/hi.txt owner=testuser group=mygrp"           
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "checksum": "279d9035886d4c0427549863c4c2101e4a63e041", 
    "dest": "/tmp/hi.txt", 
    "gid": 1032, 
    "group": "mygrp", 
    "mode": "0644", 
    "owner": "testuser", 
    "path": "/tmp/hi.txt", 
    "secontext": "unconfined_u:object_r:admin_home_t:s0", 
    "size": 9, 
    "state": "file", 
    "uid": 5000
}
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "checksum": "279d9035886d4c0427549863c4c2101e4a63e041", 
    "dest": "/tmp/hi.txt", 
    "gid": 1032, 
    "group": "mygrp", 
    "mode": "0644", 
    "owner": "testuser", 
    "path": "/tmp/hi.txt", 
    "secontext": "unconfined_u:object_r:admin_home_t:s0", 
    "size": 9, 
    "state": "file", 
    "uid": 5000
}
沒有創(chuàng)建的用戶和組時將會出現(xiàn)錯誤廉赔;

    ? fetch模塊;
從遠程主機復(fù)制文件到本地匾鸥;遠程主機不能指定多個蜡塌。
    ? command模塊;
Ansible-doc -s command
在遠程主機執(zhí)行命令扫腺,
Ansible -----chdir 切換目錄執(zhí)行岗照;
Ansible ------executable執(zhí)行程序,執(zhí)行命令有shell發(fā)起笆环,指定shell類型攒至;
Ansible ----free from  自有格式執(zhí)行;


[root@localhost ansible]#ansible all -m command -a "ifconfig"
172.16.88.1 | SUCCESS | rc=0 >>
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.226.150  netmask 255.255.255.0  broadcast 192.168.226.255
        inet6 fe80::cf19:b710:2fcd:be00  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:f6:4b:b1  txqueuelen 1000  (Ethernet)
        RX packets 3699  bytes 386609 (377.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1201  bytes 197899 (193.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
172.16.88.2 | SUCCESS | rc=0 >>
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.226.152  netmask 255.255.255.0  broadcast 192.168.226.255
        inet6 fe80::6f38:23ba:a34b:3a29  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:58:50:18  txqueuelen 1000  (Ethernet)
        RX packets 2593  bytes 258093 (252.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 450  bytes 68915 (67.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

切換目錄并創(chuàng)建目錄躁劣;
Ansible all -m command -a "chdir=/var/tmp  mkdir hi.dir"
[root@localhost ~]#ansible all -m command -a "chdir=/var/tmp/ mkdir hi.dir"
172.16.88.2 | SUCCESS | rc=0 >>


172.16.88.1 | SUCCESS | rc=0 >>

[root@localhost ~]#ansible all -m command -a "chdir=/var/tmp/ mkdir hi.dir"
172.16.88.1 | FAILED | rc=1 >>
mkdir: cannot create directory ‘hi.dir’: File exists

172.16.88.2 | FAILED | rc=1 >>
mkdir: cannot create directory ‘hi.dir’: File exists

不是冪等的迫吐,再次創(chuàng)建將會出現(xiàn)失敗账忘;

遠程主機設(shè)置密碼志膀;
[root@localhost ~]#ansible all -m command -a "echo mageedu | password --stdin mageedu"
172.16.88.1 | SUCCESS | rc=0 >>
mageedu | password --stdin mageedu

172.16.88.2 | SUCCESS | rc=0 >>
mageedu | password --stdin mageedu

指定shell類型熙宇;
[root@localhost ~]#ansible all -m command -a "echo mageedu | password --stdin mageedu excutable=/bin/bash"
172.16.88.1 | SUCCESS | rc=0 >>
mageedu | password --stdin mageedu excutable=/bin/bash

172.16.88.2 | SUCCESS | rc=0 >>
mageedu | password --stdin mageedu excutable=/bin/bash

Command 無法解析|的功能,無法使用設(shè)置密碼溉浙;

    ? Ansible-doc -s shell
查看shell模塊選項烫止;


使用shell模塊添加用戶密碼;
[root@localhost ~]#ansible all -m command -a "useradd mageedu"                                            
172.16.88.2 | SUCCESS | rc=0 >>


172.16.88.1 | SUCCESS | rc=0 >>


[root@localhost ~]#ansible all -m shell -a "echo mageedu | passwd --stdin mageedu"
172.16.88.2 | SUCCESS | rc=0 >>
Changing password for user mageedu.
passwd: all authentication tokens updated successfully.

172.16.88.1 | SUCCESS | rc=0 >>
Changing password for user mageedu.
passwd: all authentication tokens updated successfully.

    ? Ansible-doc -s file

創(chuàng)建目錄戳稽;
Ansible all -m file -a "path=/var/tmp/hello.dir state=directory"

[root@localhost ~]#ansible all -m file -a "path=/var/tmp/hello.dir state=directory"
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "gid": 0, 
    "group": "root", 
    "mode": "0755", 
    "owner": "root", 
    "path": "/var/tmp/hello.dir", 
    "secontext": "unconfined_u:object_r:user_tmp_t:s0", 
    "size": 6, 
    "state": "directory", 
    "uid": 0
}

創(chuàng)建文件馆蠕;
[root@localhost ~]#ansible all -m file -a "path=/var/tmp/hello.txt state=file"
172.16.88.1 | FAILED! => {
    "changed": false, 
    "failed": true, 
    "msg": "file (/var/tmp/hello.txt) is absent, cannot continue", 
    "path": "/var/tmp/hello.txt", 
    "state": "absent"
}
172.16.88.2 | FAILED! => {
    "changed": false, 
    "failed": true, 
    "msg": "file (/var/tmp/hello.txt) is absent, cannot continue", 
    "path": "/var/tmp/hello.txt", 
    "state": "absent"
}
創(chuàng)建空文件,不建議使用file模塊惊奇,使用copy命令互躬,countent 為空,即可拷貝空文件颂郎;

file模塊可以創(chuàng)建符號鏈接吼渡;
復(fù)制一個文件,創(chuàng)建符號鏈接乓序;
[root@localhost ~]#ansible all -m copy -a "src=/etc/fstab dest=/var/tmp/fstab.ansible"
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "checksum": "38e9d94be631342601af30347dca5d61ae09172c", 
    "dest": "/var/tmp/fstab.ansible", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "b91107d726fc7502b6d74ffce58a6dd0", 
    "mode": "0644", 
    "owner": "root", 
    "secontext": "unconfined_u:object_r:admin_home_t:s0", 
    "size": 541, 
    "src": "/root/.ansible/tmp/ansible-tmp-1505911110.34-137908123845802/source", 
    "state": "file", 
    "uid": 0
}
創(chuàng)建符號鏈接寺酪;
[root@localhost ~]#ansible all -m file -a "src=/var/tmp/fstab.ansible dest=/var/tmp/fstab.link state=link"
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "dest": "/var/tmp/fstab.link", 
    "gid": 0, 
    "group": "root", 
    "mode": "0777", 
    "owner": "root", 
    "secontext": "unconfined_u:object_r:user_tmp_t:s0", 
    "size": 22, 
    "src": "/var/tmp/fstab.ansible", 
    "state": "link", 
    "uid": 0
}
[root@localhost tmp]#ll
總用量 4
-rw-r--r--. 1 root root 541 9月  20 20:38 fstab.ansible
lrwxrwxrwx. 1 root root  22 9月  20 20:41 fstab.link -> /var/tmp/fstab.ansible

指明目標符號鏈接,state=link

File 模塊設(shè)定文件屬性竭缝;
Group,mode,owner….

    ? Ansible-doc -s cron 
cron模塊---定義計劃任務(wù)房维;
 
[root@localhost ~]#ansible all -m cron -a "minute=*/3 job='/usr/sbin/update 172.16.0.1 &> /dev/null' " 
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": [
        "None"
    ]
}

同步時間沼瘫;
[root@localhost tmp]#crontab -l
#Ansible: None
*/3 * * * * /usr/sbin/update 172.16.0.1 &> /dev/null
在node1上查看信息抬纸;

刪除設(shè)定的任務(wù);
[root@localhost ~]#ansible all -m cron -a "minute=*/3 job='/usr/sbin/update 172.16.0.1 &> /dev/null' state=absent"
172.16.88.1 | SUCCESS => {
    "changed": false, 
    "envs": [], 
    "jobs": [
        "None"
    ]
}
需要指明名字耿戚;
[root@localhost ~]#ansible all -m cron -a "minute=*/3 job='/usr/sbin/update 172.16.0.1 &>/dev/null' name=None state=absent" 
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": []
}
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": []
}
[root@localhost tmp]# crontab -l
[root@localhost tmp]#
刪除設(shè)定任務(wù)成功湿故;

    ? Ansible-doc -s yum 
Yum 模塊
State= 選項---install(present , installed , latest)
都表示安裝;
remove(absent , removed)--都表示卸載膜蛔;
Disbalerepo 禁用某個倉庫
Enablerepo 啟用沒偶個倉庫
Disable_gpg_check 禁用秘鑰檢測

兩個主機各自安裝一個nginx;
[root@localhost ~]#ansible all -m yum -a "name=nginx state=installed"
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
[root@localhost ~]#rpm -q nginx
nginx-1.10.2-1.el7.x86_64

    ? Ansible-doc -s service
service模塊坛猪;
[root@localhost ~]#ansible all -m service -a "name=nginx state=started  "           
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "name": "nginx", 
    "state": "started", 
[root@localhost ~]#ansible all -m service -a "name=nginx state=stopped  "     
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "name": "nginx", 
    "state": "stopped", 
查看剩余模塊;
Ansible-doc -l|less


    ? Ansible-doc -s script
script模塊皂股;
指定腳本路徑墅茉,執(zhí)行腳本
[root@localhost ~]#ansible all -m script -a "/tmp/test.sh"
172.16.88.1 | SUCCESS => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 172.16.88.1 closed.\r\n", 
    "stdout": "", 
    "stdout_lines": []
}
172.16.88.2 | SUCCESS => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 172.16.88.2 closed.\r\n", 
    "stdout": "", 
    "stdout_lines": []
}
[root@localhost tmp]#cat /tmp/ansible.txt 
ansible script
執(zhí)行腳本在遠程主機執(zhí)行。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末呜呐,一起剝皮案震驚了整個濱河市就斤,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌蘑辑,老刑警劉巖洋机,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異洋魂,居然都是意外死亡绷旗,警方通過查閱死者的電腦和手機喜鼓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來衔肢,“玉大人庄岖,你說我怎么就攤上這事〗侵瑁” “怎么了顿锰?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長启搂。 經(jīng)常有香客問我硼控,道長,這世上最難降的妖魔是什么胳赌? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任牢撼,我火速辦了婚禮,結(jié)果婚禮上疑苫,老公的妹妹穿的比我還像新娘熏版。我一直安慰自己,他們只是感情好捍掺,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布撼短。 她就那樣靜靜地躺著,像睡著了一般挺勿。 火紅的嫁衣襯著肌膚如雪曲横。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天不瓶,我揣著相機與錄音禾嫉,去河邊找鬼。 笑死蚊丐,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的麦备。 我是一名探鬼主播孽椰,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼凛篙!你這毒婦竟也來了黍匾?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤鞋诗,失蹤者是張志新(化名)和其女友劉穎膀捷,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體削彬,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡全庸,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年秀仲,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片壶笼。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡神僵,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出覆劈,到底是詐尸還是另有隱情保礼,我是刑警寧澤,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布责语,位于F島的核電站炮障,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏坤候。R本人自食惡果不足惜胁赢,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望白筹。 院中可真熱鬧智末,春花似錦、人聲如沸徒河。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽顽照。三九已至由蘑,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間棒厘,已是汗流浹背纵穿。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工下隧, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留奢人,地道東北人。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓淆院,卻偏偏與公主長得像何乎,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子土辩,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容

  • 一.ansible (1) ansible: ansible是一款新出現(xiàn)的自動化運維系統(tǒng)支救,基于python開發(fā)并集...
    楠人幫閱讀 1,941評論 0 8
  • ansible 系統(tǒng)架構(gòu) ansible簡介ansible是新出現(xiàn)的自動化運維工具,ansible是一個配置管理和...
    運維阿文閱讀 9,586評論 1 52
  • 作為背鍋俠運維工作的基本流程 運維工具的分類 : ansible的模塊化: ansible密鑰登陸 ansible...
    二郎5閱讀 4,156評論 0 10
  • 本文主要內(nèi)容均收集于網(wǎng)絡(luò)上的博文資料拷淘,僅以此文作為學(xué)習(xí)總結(jié)各墨。BTW,目前Ansible對python3的支持還不是...
    qiuyi943閱讀 18,234評論 1 15
  • 安裝ansible 1.yum安裝:RHEL(Centos)7版本: 2.Apt(Ubuntu)安裝方式: 3.h...
    愛吃土豆的程序猿閱讀 11,140評論 0 12