ansible软件2
第1章 copy模块
1.1 创建文件及写入内容
1. [root@m01 scripts]# ansible oldboy -m copy -a "content='wo shi hao ren' dest=/machangwei/11"
2. [root@web02 machangwei]# cat 11
3. wo shi hao ren[root@web02 machangwei]# 应该加个换行符
4.
5. [root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen sha\n' dest=/machangwei/22"
6. [root@web02 machangwei]# cat 22
7. ni hen sha
8. [root@web02 machangwei]#
1.2 创建文件改用户
[root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen\n' dest=/machangwei/33 owner=oldboy"
[root@web02 machangwei]# ll
total 12
-rw-r--r-- 1 root root 14 Oct 22 12:32 11
-rw-r--r-- 1 root root 11 Oct 22 12:34 22
-rw-r--r-- 1 oldboy root 7 Oct 22 12:38 33
[root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen\n' owner=p group=incahome dest=/machangwei/44"
[root@web02 machangwei]# ll|tail -1
-rw-r--r-- 1 p incahome 7 Oct 22 12:47 44
1.3 创建文件并修改权限
[root@m01 scripts]# ansible oldboy -m copy -a "content='ni hen\n' owner=p group=incahome dest=/machangwei/55 mode=1777"
[root@web02 machangwei]# ll|tail -1
-rwxrwxrwt 1 p incahome 7 Oct 22 12:50 55
1.4 force 没有默认覆盖
[root@m01 scripts]# ansible oldboy -m copy -a "content='xiao ming\n' owner=p group=incahome dest=/machangwei/66 mode=1777"
[root@web02 machangwei]# cat 66
xiao
[root@web02 machangwei]# cat 66
xiao ming
=no 不传送
[root@m01 scripts]# ansible oldboy -m copy -a "content='xiao ming\n' owner=p group=incahome dest=/machangwei/66 mode=1777 force=no"
[root@web02 machangwei]# cat 66
xiao ming
[root@web02 machangwei]# cat 66
xiao ming
1.5 备份
[root@web02 machangwei]# cat 88
#!/bin/sh
cat >>/etc/ansible/hosts <<eof
[oldboy]
172.16.1.7
[root@m01 scripts]# ansible oldboy -m copy -a "src=/server/scripts/xiao owner=p group=incahome dest=/machangwei/88 mode=1777 backup=yes"
[root@web02 machangwei]# ls
11 22 33 44 55 66 77 88 88.4749.2017-10-22@13:15:11~
[root@web02 machangwei]# cat 88
123 456
[root@web02 machangwei]# cat 88.4749.2017-10-22\@13\:15\:11~
#!/bin/sh
cat >>/etc/ansible/hosts <<eof
[oldboy]
172.16.1.7
172.16.1.8
1.6 复制目录
ansible oldboy -m copy -a "src=/server/scripts dest=/machangwei/"
[root@web02 machangwei]# ls
11 22 33 44 55 66 77 88 88.4749.2017-10-22@13:15:11~ scripts
[root@web02 machangwei]# cat scripts/
cat: scripts/: Is a directory
[root@web02 machangwei]# ll scripts/
total 28
-rw-r--r-- 1 root root 143 Oct 22 13:22 hosts
[root@m01 scripts]# ansible oldboy -m copy -a "src=/server/scripts dest=/machangwei/ directory_mode=0777" 远端有目录的权限不变,没有
的建为0777
1.7 复制文件并改名
[root@m01 scripts]# echo 45678 >mama
[root@m01 scripts]# cat mama
45678
[root@m01 scripts]# ansible oldboy -m copy -a "src=/server/scripts/mama dest=/machangwei/10"
[root@web02 machangwei]# cat 10
45678
1.8 总结
copy模块在ansible里的角色就是把ansible执行机器上的文件拷贝到远程节点上。 
与fetch模块相反的操作。
| 参数名 | 是否必须 | 默认值 | 选项 | 说明 | 
| src | no | 用于定位ansible执行的机器上的文件,需要绝对路径。如果拷贝的是文件夹,那么文件夹会整体拷贝,如果结尾是”/”,那么只有文件夹内的东西被考过去。一切的感觉很像rsync | ||
| content | no | 用来替代src,用于将指定文件的内容,拷贝到远程文件内 | ||
| dest | yes | 用于定位远程节点上的文件,需要绝对路径。如果src指向的是文件夹,这个参数也必须是指向文件夹 | ||
| backup | no | no | yes/no | 备份远程节点上的原始文件,在拷贝之前。如果发生什么意外,原始文件还能使用。 | 
| directory_mode | no | 这个参数只能用于拷贝文件夹时候,这个设定后,文件夹内新建的文件会被拷贝。而老旧的不会被拷贝 | ||
| follow | no | no | yes/no | 当拷贝的文件夹内有link存在的时候,那么拷贝过去的也会有link | 
| force | no | yes | yes/no | 默认为yes,会覆盖远程的内容不一样的文件(可能文件名一样)。如果是no,就不会拷贝文件,如果远程有这个文件 | 
| group | no | 设定一个群组拥有拷贝到远程节点的文件权限 | ||
| mode | no | 等同于chmod,参数可以为“u+rwx or u=rw,g=r,o=r” | ||
| owner | no | 设定一个用户拥有拷贝到远程节点的文件权限 | 
参数返回值
| 参数名 | 参数说明 | 返回值 | 返回值类型 | 样例 | 
| src | 位于ansible执行机上的位置 | changed | string | /home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source | 
| backup_file | 将原文件备份 | changed and if backup=yes | string | /path/to/file.txt.2015-02-12@22:09~ | 
| uid | 在执行后,拥有者的ID | success | int | 100 | 
| dest | 远程节点的目标目录或文件 | success | string | /path/to/file.txt | 
| checksum | 拷贝文件后的checksum值 | success | string | 6e642bb8dd5c2e027bf21dd923337cbb4214f827 | 
| md5sum | 拷贝文件后的md5 checksum值 | when supported | string | 2a5aeecc61dc98c4d780b14b330e3282 | 
| state | 执行后的状态 | success | string | file | 
| gid | 执行后拥有文件夹、文件的群组ID | success | int | 100 | 
| mode | 执行后文件的权限 | success | string | 0644 | 
| owner | 执行后文件所有者的名字 | success | string | httpd | 
| group | 执行后文件所有群组的名字 | success | string | httpd | 
| size | 执行后文件大小 | success | int | 1220 | 
第2章 command模块
command 模块用于运行系统命令,比如echo hello, 你安装在系统里的python,或者make 一类。大家能领悟就行了。
2.1 常用参数:
| parameter | required | default | choices | comments | 
| chdir | no | 运行command命令前先cd到这个目录 | ||
| creates | no | 如果这个参数对应的文件存在,就不运行command | ||
| executable | no | 将shell切换为command执行,这里的所有命令需要使用绝对路径 | ||
| removes | no | 如果这个参数对应的文件不存在,就不运行command | 
2.2 切换到目录下操作
[root@m01 scripts]# ansible oldboy -m command -a "ls" 家目录
172.16.1.8 | SUCCESS | rc=0 >>
1.txt
2
2.txt
[root@m01 scripts]# ansible oldboy -m command -a "chdir=/machangwei/ ls"
172.16.1.31 | SUCCESS | rc=0 >>
10
11
1.t
22
33
44
55
66
77
88
2.3 cteates
[root@m01 scripts]# ansible oldboy -m command -a "touch creates /machangwei/cc"
[root@m01 scripts]# ansible oldboy -m command -a "touch /machangwei/aa creates"
第3章 cron模块
主要是用来对定时任务进行调度,定时任务模块会包含一句描述信息,格式如下:
| "#Ansible: <name>" | 
name对应的为模块传递过去的参数,主要用来给以后ansible进行操作的时候,查看相关的状态或者检查相关状态
依赖的模块为cron
| 参数 | 必填 | 默认 | 选择 | 说明 | 
| Backup | 非 | Yes/no | 如果yes,那么在修改之后会进行备份,备份的路径在backup_file | |
| Cron_file | 非 | 如果设置了,那么在cron.d中使用此文件替代单独用户的crontab,在使用此选项的时候,必须使用user选项 | ||
| Day | 非 | 天 | ||
| Hour | 非 | 小时 ( 0-23, *, */2, etc ) | ||
| Job | 非 | 需要执行的命令,必须状态为present | ||
| Minute | 非 | 分 ( 0-59, *, */2, etc ) | ||
| Month | 非 | 月( 1-12, *, */2, etc ) | ||
| Name | 非 | 任务的描述 | ||
| Reboot | 非 | No | Yes/no | 重启后是否需要执行 | 
| Special_time | 非 | reboot yearly annually monthly weekly daily hourly | 特定的执行时间 | |
| State | 非 | Present | Present Absent | 启用或停用任务 | 
| User | 非 | Root | 执行任务的用户 | |
| Weekday | 非 | 每一周的哪天进行运行(0-6 for Sunday-Saturday, *, etc) | 
3.1 定时任务创建
[root@m01 scripts]# ansible oldboy -m cron -a "name='chuang jian ding shi ren wu' minute=5 job='/bin/sh /machangwei/hostname.sh >/dev/null 2>&1'"
[root@web02 machangwei]# crontab -l|tail -2
#Ansible: chuang jian ding shi ren wu
5 * * * * /bin/sh /machangwei/hostname.sh >/dev/null 2>&1
3.2 删除定时任务
[root@m01 scripts]# ansible oldboy -m cron -a "name='chuang jian ding shi ren wu' minute=5 job='/bin/sh /machangwei/hostname.sh >/dev/null 2>&1' state=absent"
[root@web02 machangwei]# crontab -l
#time sync by oldboy at 2010-2-1
*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
[root@web02 machangwei]#
[root@m01 scripts]# ansible oldboy -m cron -a "name='chuang jian ding shi ren wu' state=absent" 有名字就可以
第4章 setup模块
这个模块在playbook中自动被查找的,从而得到远程主机的相关信息,可以作为变量使用。
| 参数 | 必填 | 默认 | 选择 | 说明 | 
| Fact_path | 否 | /etc/ansible/facts.d | Fact的路径 | |
| Filter | 否 | * | 过滤串 | 
4.1 收集主机网卡信息
[root@m01 scripts]# ansible oldboy -m setup -a "filter=ansible_eth[02]"
172.16.1.8 | SUCCESS => {
"ansible_facts": {
"ansible_eth0": {
"active": true,
"device": "eth0",
"features": {
"fcoe_mtu": "off [fixed]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "on",
"highdma": "off [fixed]",
"large_receive_offload": "off [fixed]",
"loopback": "off [fixed]",
"netns_local": "off [fixed]",
"ntuple_filters": "off [fixed]",
"receive_hashing": "off [fixed]",
"rx_checksumming": "on",
"rx_vlan_filter": "on [fixed]",
"rx_vlan_offload": "on [fixed]",
"scatter_gather": "on",
"tcp_segmentation_offload": "on",
"tx_checksum_fcoe_crc": "off [fixed]",
"tx_checksum_ip_generic": "on",
"tx_checksum_ipv4": "off",
"tx_checksum_ipv6": "off",
"tx_checksum_sctp": "off [fixed]",
"tx_checksum_unneeded": "off",
"tx_checksumming": "on",
"tx_fcoe_segmentation": "off [fixed]",
"tx_gre_segmentation": "off [fixed]",
"tx_gso_robust": "off [fixed]",
"tx_lockless": "off [fixed]",
"tx_scatter_gather": "on",
"tx_scatter_gather_fraglist": "off [fixed]",
"tx_tcp6_segmentation": "off",
"tx_tcp_ecn_segmentation": "off",
"tx_tcp_segmentation": "on",
"tx_udp_tnl_segmentation": "off [fixed]",
"tx_vlan_offload": "on [fixed]",
"udp_fragmentation_offload": "off [fixed]",
"vlan_challenged": "off [fixed]"
},
"ipv4": {
"address": "10.0.0.8",
"broadcast": "10.0.0.255",
"netmask": "255.255.255.0",
"network": "10.0.0.0"
},
"ipv6": [
{
"address": "fe80::20c:29ff:fecf:1335",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "00:0c:29:cf:13:35",
"module": "e1000",
"mtu": 1500,
"pciid": "0000:02:01.0",
"promisc": false,
"speed": 1000,
"type": "ether"
}
},
"changed": false
}
4.2 收集fact并且进行保存
| ansible pythonserver -m setup --tree /tmp/facts | 
执行之后,会显示相关的fact,并且在/tmp/facts中会保存fact信息,如下:
| [root@ansibleserver tmp]# ls -l /tmp/facts/ total 12 -rw-r--r-- 1 root root 8990 Jan 18 13:16 192.168.1.60 | 
使用--tree选项,在分类的时候,会根据主机的名称进行分类
收集内存信息并输出
[root@ansibleserver tmp]# ansible pythonserver -m setup -a "filter=ansible_*_mb"
SSH password:
192.168.1.60 | success >> {
"ansible_facts": {
"ansible_memfree_mb": 746,
"ansible_memtotal_mb": 996,
"ansible_swapfree_mb": 2015,
"ansible_swaptotal_mb": 2015
},
"changed": false
}
第5章 ping 模块
ping模块主要是无意义的测试模块,主要用来检查ansible是否可以用的模块以及python是否配置好的,在playbook中基本不会使用,在能成功连接之后,总是返回结果pong
[root@m01 scripts]# ansible oldboy -m ping
172.16.1.8 | SUCCESS => {
"changed": false,
"ping": "pong"
}
第6章 用户模块
用户模块主要用来管理用户账号和用户的属性(对远程主机用户进行批量管理)。
用户模块依赖的指令为useradd,userdel,usermod
| 参数 | 必填 | 默认值 | 选项 | 说明 | 
| Append | 否 | No | Yes/no | 如果没有指定group,append设定为yes,那么会添加到用户同名组;append设定为no,那么会添加到user组。如果指定了group,那么都会添加在指定的group组 | 
| Comment | 否 | 用户的备注信息 | ||
| Force | 否 | No | Yes/no | 当状态为absent的时候,相当于userdel -force | 
| generate_ssh_key | 否 | No | Yes/no | 是否生成秘钥 | 
| Group | 否 | 可选的,设定用户的主组 | ||
| Groups | 否 | 用逗号分隔的组,当groups设定为空的时候,那么会移除除了主组的其他所有组 | ||
| Home | 否 | 可选的,设定为用户的home目录 | ||
| Login_class | 否 | 可选的,设定用户的登录类 FreeBSD, OpenBSD and NetBSD systems. | ||
| Name | 是 | 用户创建,移除,修改 | ||
| Move_home | 否 | No | Yes/no | 如果使用了选项home=设置为yes,那么会将用户家目录移到不存在的home目录中 | 
| Non_unique | 否 | No | Yes/no | 可选的,当使用-u选项的时候,将用户的uid设置为non_unique | 
| Password | 否 | 设定用户的密码 | ||
| Remove | 否 | No | Yes/no | 当使用状态为state=absent的时候,差不多和userdel --remove(删除所有信息) | 
| Shell | 否 | 设定用户的shell | ||
| Ssh_key_bits | 否 | 2048 | 设定秘钥的位数 | |
| Ssh_key_comments | 否 | ¥HOSTHOME | Ssh key备注信息 | |
| Ssh_key_file | 否 | .sha/id_rsa | 秘钥的文件名 | |
| ssh_key_passphrase | 否 | Ssh秘钥的密码 | ||
| Ssh_key_type | 否 | Rsa | Ssh秘钥的类型 | |
| State | 否 | Present | Present Absent | 新增删除 | 
| System | 否 | No | Yes/no | 创建为系统账号,不会改变已经存在的用户 | 
| Uid | 否 | 设定为用户的uid | ||
| Update_password | 否 | Always | Always On_create | Always当用户 | 
6.1 添加用户
[root@m01 scripts]# ansible oldboy -m user -a "name=xixi"
[root@web02 machangwei]# id xixi
uid=1003(xixi) gid=1003(xixi) groups=1003(xixi)
[root@m01 scripts]# ansible oldboy -m user -a "name=dong uid=576"
[root@web02 machangwei]# id dong
uid=576(dong) gid=576(dong) groups=576(dong)
[root@m01 scripts]# ansible oldboy -m user -a "name=nan group=xixi uid=579 comment='li li li'"
172.16.1.8 | SUCCESS => {
"changed": true,
"comment": "li li li",
"createhome": true,
"group": 1003,
"home": "/home/nan",
"name": "nan",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 579
}
[root@m01 scripts]# ansible oldboy -m user -a "name=bei group=xixi shell=/sbin/nologin/"
172.16.1.8 | SUCCESS => {
"changed": true,
"comment": "",
"createhome": true,
"group": 1003,
"home": "/home/bei",
"name": "bei",
"shell": "/sbin/nologin/",
"state": "present",
"system": false,
"uid": 1004
}
[root@m01 scripts]# ansible oldboy -m user -a "name=shang groups=xixi append=yes" 多个组
6.2 删除用户
[root@m01 scripts]# ansible oldboy -m user -a "name=shang state=absent remove=yes"
将用户强制删除
第7章 file模块
在之前ansible命令行的时候有copy模块,在playbook的时代自然也有一个模块专门负责文件的拷贝,当然这个时代它不仅仅是文件拷贝那么简单。
来自官方的解释:
file模块它包含了文件、文件夹、超级链接类的创立、拷贝、移动、删除操作。
常用参数:
| 参数名 | 是否必须 | 默认值 | 选项 | 说明 | 
| follow | no | no | yes/no | 如果原来的文件是link,拷贝后依旧是link | 
| force | no | no | yes/no | 强制执行,没说的 | 
| group | no | 设定一个群组拥有拷贝到远程节点的文件权限 | ||
| mode | no | 等同于chmod,参数可以为“u+rwx or u=rw,g=r,o=r” | ||
| owner | no | 设定一个用户拥有拷贝到远程节点的文件权限 | ||
| path | yes | 目标路径,也可以用dest,name代替 | ||
| src | yes | 待拷贝文件/文件夹的原始位置。 | ||
| state | no | file | file/link/directory/hard/touch/absent | file代表拷贝后是文件;link代表最终是个软链接;directory代表文件夹;hard代表硬链接;touch代表生成一个空文件;absent代表删除 | 
修改文件的所有组、人、权限。
- file: path=/etc/foo.conf owner=foo group=foo mode=0644
# 操作链接的案例
- file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
#参数化案例
- file: src=/tmp/{{ item.path }} dest={{ item.dest }} state=link
with_items:
- { path: 'x', dest: 'y' }
- { path: 'z', dest: 'k' }
# 使用touch来创建一个空文件并定义权限
- file: path=/etc/foo.conf state=touch mode="u=rw,g=r,o=r"
# touch一个空文件,并且修改权限
- file: path=/etc/foo.conf state=touch mode="u+rw,g-wx,o-rwx"
7.1 创建目录
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/dong state=directory"
172.16.1.41 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/machangwei/dong",
"size": 4096,
"state": "directory",
"uid": 0
[root@web02 machangwei]# ls
bb cc dd dong hostname.sh
7.2 创建多级目录
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/s/s/d/f state=directory"
172.16.1.31 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/machangwei/s/s/d/f",
"size": 4096,
"state": "directory",
"uid": 0
}
7.3 创建文件
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/ming state=touch"
172.16.1.8 | SUCCESS => {
"changed": true,
"dest": "/machangwei/ming",
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"size": 0,
"state": "file",
"uid": 0
}
7.4 创建软链接
[root@m01 scripts]# ansible oldboy -m file -a "src=/machangwei/ming dest=/machangwei/sisi state=link"
172.16.1.8 | SUCCESS => {
"changed": true,
"dest": "/machangwei/sisi",
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"size": 16,
"src": "/machangwei/ming",
"state": "link",
"uid": 0
}
7.5 删除文件目录
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/ming state=absent"
172.16.1.31 | SUCCESS => {
"changed": true,
"path": "/machangwei/ming",
"state": "absent"
[root@m01 scripts]# ansible oldboy -m file -a "dest=/machangwei/a state=absent"
172.16.1.8 | SUCCESS => {
"changed": true,
"path": "/machangwei/a",
"state": "absent"
} a是多级目录
第8章 fetch模块
8.1 拉取文件
[root@m01 scripts]# ansible oldboy -m fetch -a "src=/machangwei/bb dest=/server/scripts/"
172.16.1.8 | SUCCESS => {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/server/scripts/172.16.1.8/machangwei/bb",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"remote_md5sum": null
[root@m01 scripts]# ansible oldboy -m fetch -a "src=/machangwei/dong dest=/server/scripts/"
172.16.1.41 | SUCCESS => {
"changed": false,
"file": "/machangwei/dong",
"msg": "remote file is a directory, fetch cannot work on directories"目录不可啦
[root@m01 scripts]# ansible oldboy -m fetch -a "src=/machangwei/bb dest=/server/scripts/"
172.16.1.8 | SUCCESS => {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/server/scripts/172.16.1.8/machangwei/bb",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"remote_md5sum": null
}
第9章 mount模块
[root@m01 scripts]# ansible oldboy -m mount -a "fstype=nfs opts=ro src=172.16.1.31:/data path=/mnt state=mounted"
172.16.1.8 | SUCCESS => {
"changed": true,
"dump": "0",
"fstab": "/etc/fstab",
"fstype": "nfs",
"name": "/mnt",
"opts": "ro",
"passno": "0",
"src": "172.16.1.31:/data"
}
[root@web02 tmp]# tail -2 /etc/fstab
proc /proc proc defaults 0 0
172.16.1.31:/data /mnt nfs ro 0 0
卸载
[root@m01 scripts]# ansible oldboy -m mount -a "fstype=nfs opts=ro src=172.16.1.31:/data path=/mnt state=unmounted"
第10章 shell模块
shell模块和command模块功能类似,但是shell模块可以识别一些特殊符号信息 > >> | * ^
[root@m01 scripts]# ansible oldboy -m shell -a "cd /machangwei;pwd;hostname"
172.16.1.41 | SUCCESS | rc=0 >>
/machangwei
backup
第11章 yum模块
ansible oldboy -m yum -a "name=nmap state=installed"
| 参数名 | 是否必须 | 默认值 | 选项值 | 参数说明 | 
| conf_file | 不 | 设定远程yum执行时所依赖的yum配置文件 | ||
| disable_gpg_check | 不 | No | Yes/No | 在安装包前检查包,只会影响state参数为present或者latest的时候 | 
| list | No | 只能由ansible调用,不支持playbook,这个干啥的大家都懂 | ||
| name | Yes | 你需要安装的包的名字,也能如此使用name=python=2.7安装python2.7 | ||
| state | no | present | present/latest/absent | 用于描述安装包最终状态,present/latest用于安装包,absent用于remove安装包 | 
| update_cache | no | no | yes/no | 用于安装包前执行更新list,只会影响state参数为present/latest的时候 | 
第12章 service模块
ansible oldboy -m service -a "name=crond state=stop enabled=no"
第13章 script模块
参考:
http://blog.csdn.net/kellyseeme/article/details/50539312
http://blog.csdn.net/wanghailong041/article/details/45770359
http://10786462.blog.51cto.com/10776462/1886774
第14章 我的第一个剧本
14.1 nfs自动化剧本
- hosts: oldboy
tasks:
- name: step01
yum: name=rpcbind state=installed
- name: step02
yum: name=nfs-utils state=installed
- hosts: 172.16.1.31
tasks:
- name: step03
copy: content="/data/ 172.16.1.0/24(rw,sync)" dest=/etc/exports
- name: step04
shell: mkdir -p /data;chown nfsnobody.nfsnobody /data
- name: step05
command: /etc/init.d/rpcbind start
- name: step06
command: /etc/init.d/nfs start
- name: step07
shell: ps -ef|grep nfs
- name: step11
copy: content="wo hen shan liang" dest=/data/oldboy.txt
- hosts: nfs-C
tasks:
- name: step08
command: /etc/init.d/rpcbind start
- name: step09
shell: mount -t nfs 172.16.1.31:/data /mnt
- name: step10
command: df -h
- hosts: 172.16.1.7
tasks:
- name: step12
command: touch /mnt/11
- hosts: 172.16.1.8
tasks:
- name: step13
command: touch /mnt/22
- hosts: 172.16.1.41
tasks:
- name: step14
command: touch /mnt/33
- hosts: 172.16.1.31
tasks:
- name: step15
command: ls -l /data/
ansible软件2的更多相关文章
- ansible软件相关模块丶计划任务,剧本
		软件相关模块 yum rpm 和yum 的区别 rpm:redhat package manager yum可以解决依赖关系 yum 源配置 [epel] name=Extra Packages fo ... 
- ansible 软件相关模块,剧本
		软件相关模块 yum rpm和yum的区别 rpm:redhat package manager yum 可以解决依赖关系 yum 源配置 使用yum下载时需要先下载epel [epel] name= ... 
- ansible软件部署
		每一个软件或集群都创建一个单独的角色. mkdir -pv ansible/roles/{jdk,hadoop,spark}/{tasks,files,templates,meta,handlers, ... 
- ansible批量管理软件部署及剧本
		服务器版本信息: Centos6.9 [root@db02 ~]# uname -a Linux db02 -.el6.x86_64 # SMP Tue Mar :: UTC x86_64 x86_6 ... 
- Linux中ansible批量管理软件部署及剧本编写
		服务器版本信息: Centos6.9 [root@db02 ~]# uname -a Linux db02 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29: ... 
- Ansible系列(六):各种变量定义方式和变量引用
		本文目录:1.1 ansible facts1.2 变量引用json数据的方式 1.2.1 引用json字典数据的方式 1.2.2 引用json数组数据的方式 1.2.3 引用facts数据1.3 设 ... 
- ansible服务部署与使用
		第1章 ssh+key实现基于密钥连接(ansible使用前提) 说明: ansible其功能实现基于SSH远程连接服务 使用ansible需要首先实现ssh密钥连接 1.1 部署ssh ... 
- ansible服务及剧本编写
		第1章 ansible软件概念说明 python语言是运维人员必会的语言,而ansible是一个基于Python开发的自动化运维工具 (saltstack).其功能实现基于SSH远程连接服务:ansi ... 
- Ansible自动化运维工具-上
		[Ansible特点] 1)Ansible与saltstack均是基于Python语言开发的 2)安装使用简单,基于不同插件和模块实现各种软件,平台,版本的管理以及支持虚拟容器多层级的部署 3)不需要 ... 
随机推荐
- OpenStack Grizzly详细安装指导
			一.环境介绍: 控制节点 eth0 (10.10.10.51), eth1 (192.168.100.51) 网络节点 eth0 (10.10.10.52), eth1 (10.20.20.52), ... 
- Sequelize-nodejs-12-Migrations
			Migrations迁移 Just like you use Git / SVN to manage changes in your source code, you can use migratio ... 
- [图解tensorflow源码] 线程池模块分析 (CPU thread pool device)
- 微信公众号开发 [03] 结合UEditor实现图文消息群发功能
			0.写在前面的话 如何实现微信平台后台管理中的,图文消息发送功能? 大概的过程如下: 通过类似表单的形式,将文章各部分内容提交到后台,封装成一个实体类,并持久化到数据库中 需要推送的时候,将不同的文章 ... 
- [转]超级强大的SVG SMIL animation动画详解
			超级强大的SVG SMIL animation动画详解 本文花费精力惊人,具有先驱前瞻性,转载规则以及申明见文末,当心予以追究.本文地址:http://www.zhangxinxu.com/wordp ... 
- UWP 播放直播流 3MU8
			UWP 播放直播流 3MU8 参考:http://www.c-sharpcorner.com/UploadFile/2b876a/http-live-streaming-in-windows-10-u ... 
- 2017-2018-2 20155315《网络对抗技术》Exp4:恶意代码分析
			实验目的 是监控你自己系统的运行状态,看有没有可疑的程序在运行. 是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals,systracer套件 ... 
- python基础学习1-列表推导式和字典推导式
			#!/usr/bin/env python # -*- coding:utf-8 -*- #列表推导式 取得100内可以被2整除且不能被3整除的数字 a=[i for i in range(100) ... 
- Django中表单的用法深探
			[转载说明:原文排版不是很好,为方便阅读,改进了排版] django的表单设计真的很棒,涉及非常多的功能,今天介绍django较为主流的几种表单使用方法.注:本文中表单与form通用.模型与model ... 
- VirtualBOX启动错误the vm session was closed before any attempt to power it on解决办法
			昨天晚上笔记本休眠后,今天早上启动vm时,报错了. 点击详细启动错误:the vm session was closed before any attempt topower it on. 解决办法: ... 
