1. ansible特性:
- ansible糅合了很多老牌运维东西的优点,根本上pubbet和saltstack能结束的功能悉数能结束。
- 安置简略:不需求在被管控主机上设备任何客户端,操作客户端时直接作业指令。
- 依据python言语结束,有Paramiko, PyYAML和Jinja2三个要害模块。
- 模块化:调用特定模块结束特定使命。可运用任意言语开发模块,且支撑自界说模块。
- 运用yaml言语定制剧本playbook。
- 依据SSH作
2. ansibl线程e的模块
- connection plugins:联接插件,经过ssh办法
- host inventory:主机清单,要处理的主机
- playbooks:剧本,yaml格局的配备文件线程撕裂者
- core modules:核NPM心模块
- custom modules:自界说模http 302块
- plugins:插件
– emailhttps认证:发送邮件。
– loggings:记录日志
3缓存视频怎样下载到手机相册. 设备
ansible放置方位:
- 外网主机:可经过VPN联接为内网缓存视频怎样转入本地视频主机进行处理
- 内网主机缓存视频变成本地视频:直接处理
ansible的设备:
配备好eHTTPSpel源,直接经过yum设https认证备
~]# yum -y ins女配美炸天tall ansible
ansible的配备文缓存视频兼并app下载件:/etc/ansible/ansihttps和http的差异ble.cfg
ansible的主机清单:/etc/ansible/hosts
**ansib线程的几种状况le的主程序:**ansible、ans缓存视频怎样转入本地视频ible-playbos、ansible-doc
4. ansible指令的运用:https和http的差异
[root@nfs ~]# ansible -h
Usage: ansible <host-pattern> [opti线程池面试题ons]
Option线程和进程的差异是什么s:
-a MODULE_ARGS, --args=MO线程安全DULE_A线程安全RGS
module arguments 模块参数
-C, --check don't make any changes; instead, try to predict some
of the changes that may occu女配没有求生欲r 干跑方法线程和进程的差异是什么
-m MODULE_NAME, --module-name=MODULE_NAME
module name to execute (defau线程安全lt=command) 指定模块称谓
--syntaxhttp 302-check perform a syntax check on the playbook, but do not execute it
语法检测
-f FORKS, --forks=FORKS
specify number of parallel processes to use (de女配每天都在抱大腿我要成仙fault=5)
一起启用多少个线程,默许5个
-u REMOTE_USER, --user=REMOTE_USER
conn线程池原理ect as this user (default=None)
-c CONNECTION, --connection=CONNECTION
connection ty线程池面试题pe to use (defauhttps协议lt=smart)
--list-hosts outputs a list of matching hosts; does not execu线程池面试题te anything else
列出主机列表,不做其他任何处理女配没有求生欲藤萝为枝。
-b, --become run operations withhttps域名 become (does not imply password prompting)
5. 界说主机列表:
示例1. 经过直接指定主机名或IP地址界说主https和http的差异机列表。
# Ex 1: Ungrouped线程安全 hosts, specify before any gro女配没有求生欲up headers.
## green.examphttpclientle.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10
示例2. 先界说组名,再在线程池面试题组下填入主机名或IP地址
# Ex 2: A collection of hosts belonging to the 'webser男配每天都在体内成果vers' group
## [webse女配没有求生欲rvers]
## alpha.example.org
## bethttp://www.baidu.coma.example.org
## 192.168.1.100
## 192.168.1.110
# If you have multiple hosts following a pattern you can specify
# them like this:
# 假定有多个接连主机,也可用如下办法指http署理定主机。
#女配每天都在为国争光# www[001:006].example.com
示例3.
# Ex 3: A coll缓存视频怎样转入本地视频ection of database servers in the 'dbservers' group
## [dbserhttps认证vhttpwatcher缓存视频怎样下载到手机相册s]
##
## db01.intranet.mydomain.net
## db02.intranet.mydo缓存视频怎样转入相册main.net
## 10.25.1.56缓存视频在手机哪里找
## 10.25.1.57
# Here's another example of host ranges,https协议 this time th线程池的七个参数ere are no
# leading 0s:
## db-[99:101]-no缓存的视频怎样保存到本地de.example.com
## 以上写法可扩展为如下主机:
## db-99-nod.example.com
## db-100-nod.example.com
## db-101-nod.example.com
定http协议义主机列表示例1:
[root@nfs ~]#缓存视频兼并app下载 tail -2 /etc/ansible/hosts
np[1:2].lxk.com
nfs.lxk.com
获取主http 302机列表:
[root@nfs ~]# ansible all --li缓存视频在手机哪里找st-hosts
hosts (3):
np1.lxk.com
np2.lxk.com
nfs.线程池的七个参数lxk.com
界说主机列表2:
[root@nfs ansible_workshop]# tail -8 /etc/ansible/hosts
[db]
node1.lxk.com
node2.lxk.com
[web]
np1.女配美炸天lxk.com
np2http://192.168.1.1登录.lxk.com
[nfs]
nfs.lxk.com
获取主机列表:
[root@nfs ansible_workshop]# ansible alhttps安全问题l --list-hosts
hosts (5):
node1.lxk.com
node2.lxk.缓存com
np1.lxk.com
np2.lxk.com
nfs.lxk.com
[root@nfs ansible_workshop]# ansible db --list-hosts
hosts (2):
node1.lxkHTTPS.com
node2.lxk.com
[root@nf线程池s ansible_workshop]# ansible we缓存视频怎样下载到手机相册b --list-hosts
hosts (2):
np1.lxk.女配没有求生欲com
np2.lxk.com
6. ansible的http 302常用模块:
获取模块帮助信息:
[root@nfs ~]# ansible-doc --http 500help
Usage: ansible-doc [-l|-F|-s]缓存是什么意思 [options] [plugin]
plugin documentation tool
Options:
-a, --all **For inter女配每天都在抱大腿我要成仙nal testing only** Show documentation for
all plugins. #内测运用
-h, --he女排名单lp s缓存视频变成本地视频how this help message and exit
-l, --list List available plugins 闪现可用插件
-女配美炸天sHTTP, --snippet Show playbook snip线程安全pet f缓存数据能够铲除吗or specified plugin(s)
## 闪现指定插件用法
获取模块列表:
~]# ansible-doc -l
6.1 ping模块:勘探长途主机
[root@nfs ~]# ansible-doc -s ping
- name: Trhttps域名y to connect to host, verify a usable python and return `pong' on success
# 测验联接主机,若方针主机可用,就回应一个'pong'
ping:
data: # Data to return for the `pinhttp 404g' return value. If this parameter is set to `cras线程和进程的差异是什么h', the module will cause an exception.
**示例1:**向悉数可控主机主张ping线程池的七个参数操作
[root@n线程和进程的差异是什么fs ~]# ansible all -m ping
np2女配每天都在为国争光.lxk.com | SUCCESS => {
"changed": false,
"ping": "pong"
}
nfs.lxk.com | SUCCESS => {
"changed": false,
"ping": "pong"缓存
}
np1.lxk.com | SUCCESS => {
"changed": false,
"ping": "pong"
}
**示例2:**data自界说回显内容为abc
[root@nfs ~]# ansible all -m ping -a data='abc'
np1.lxk.com | SUCCESS => {缓存数据能够铲除吗
"changed": false,
"ping": "abc"
}
np2.lxk.com | SUCCESS => {
"ch线程池面试题angehttpclientd": false,
"ping"https和http的差异: "abc"
}
nfs.lxk.com | SUCCESS => {
"changed": false,
"ping": "abc"
}
**线程安全示例3:*d缓存视频变成本地视频ata为http://192.168.1.1登录crash时,闪现成果为falseHTTPS
[root@nfs ~]# ansible all -mhttpwatch ping -a data=https和http的差异'crash'
np1.lxk.com | FAILED! => {
"changed": false,
"module_http署理stderr": "Shared connection to np1.lxk.com closed.rn",
"module_stdout": "Traceba缓存数据能够铲除吗ck (most线程安全 recent cahttp协议ll last):rn File "/tmp/ansible_2DLaM3/ansible_module_ping.py", line 84, in <module>rn m线程是什么意思ain线程池面试题()rn File女配每天都在抱大腿我要成仙 "/tmp/ansible_2DLaM3/ansi线程池ble_http署理mo缓存视频怎样转入本地视频dule_ping.py", line 74, in maihttps域名nrn raise Exception("boom")rnException: boomrn",
"msg": "MODULE FAILURE",
"rc": 1
}
nfs.lxk.com | FAILED! => {
"changed": fa女排名单lse,
"mo线程dule_stderr": "Shared connection to nfs.lxk.com closed.rn",
"module_stdout": "Traceb缓存是什么意思ack (most recent call last):http://192.168.1.1登录rn File "/tmp/ansible_imV6B2/ansible_module_ping.py线程的几种状况", line 84, in <module线程池创立的四种>rn main()rn File "/tmp/ansible_httpwatchimV6B2缓存是什么意思/ansible_module_ping.py", line 74, in mainrn raise Exception("boom")rnException: boomrn",
"msg": "MODULE FAILURE",女配每天都在抱大腿我要成仙
"rc": 1
}
np2.lxk.co女配没有求生欲藤萝为枝m | FAILED! => {
"changed":http署理 false,
"module_stderr": "Shared connection to np2.lxk.com closed.rn",
"module_stdout": "Traceback (most recent call last):rn File "/tmp/ansible_iocghttp 3022P/ansible_module_ping.py", lihttps和http的差异ne 84, in <module>rn main()rn File "/tmp/ansible_iocg2P/ansi女配每天都在抱大腿我要成仙ble_module_ping.py", line 74, in mainrn raise Excephttp协议tion("boom")rnException: boomrn",
"msg": "MODULE FAILUREhttpwatch",
"rc": 1
}
6.2 command模块:在长途主机缓存数据能够铲除吗上作业指令
模块用法:
关于command来说,要运用哪个指令,运用-a选项,直接给出指令本身即可。
例1:创立临时文件
[root@nfs ~]http://www.baidu.com# ansible all -m command -a "mktemp /tmp/abc.XXXX"
nfs.lxk.com | SUCCESS | rc=0 >>
/tmp/abc.Xyz7
np2.lxk.com | SUCCESS | rc=0 >>
/tm缓存视频怎样下载到手机相册p/abc.lwqo
np1.lxk.com | SUCCESS | rc=0 >>
/tmp/abc.jjHW
例2:创立用户
[root@nfs ~]# ansible all -m command -a "useradd user1" # 第一次创立成功
nfs.lxk.com | SUCCESS | rc线程池创立的四种=0 >>
np1.lxk.com | SUCCESS | rc=0 >>
np2.lxk.com | SUCCESS | rc=0 >>
[rhttpwatchoot@nfs ~]# ansible all -m commanhttpclientdhttp协议 -a "useradd user1" #第2次创立相同用http 302户失利
nfs.https认证lxk.com | FAILED | rc=9 >>
useradd: user 'user1' already existsnon-zero return code
np1.lxk.com | FAILED | rc=9 >>
useradd: user 'user1' already existsnon-zero return code
np2.lxk.女配美炸天com | FAILED | rc=9 >>
useraddhttp 302: ushttp协议er 'user1' already existsnon-zero return code
用加条件判别创立用户失利缓存视频兼并,因||是直接发给方针主机内核作业,不是经由shell作业,而||是shhttp协议ell的内置指令。
[root@nfs ~]# ansible all -m command -a "id user1 || useradd user1"
nfs.lxk.com | FAILED | rc=1 >>
id: extra operand ‘||’
Try 'id --help' for more information.non-zero retur女配满眼都是钱n code
np1.lxk.com缓存视频兼并 | FAILED |线程和进程的差异是什么 rc=1 >>
id: extra op女配没有求生欲erand ‘||’
Try 'id --help' for more information.non-zero return code
np2.lxk.com | FAILED | rc=1 >&http://www.baidu.comgt;
id: extra operand ‘||’
Try 'id --help' for mor缓存视频兼并e information.non-zero return code
6.3 shell模块:在节点中履行指令
与c线程撕裂者ommand模块很类似,所不同处是它是在shell下作业的。还可运用executable切换至指女配没有求生欲藤萝为枝定node下作业指令。
**例:**加条件判别创立用户
[root@nfs ~]# ansible all -m shell -a "id user1 || useradd user1"
np2.lxk.com | SU女配没有求生欲晋江CCESS | rc=0 >>httpclient
uid=1001(uhttpwatchser1) gid=1001(user1) groups=1001(user1)
nfs.lxk.com | SUCCESS | rc=0 >>
uid=1000(user1) gid=1000(user1) groups=1000(user1)
np1.lxk.com | SUCCESS | rc=0 >>
uid=1000(user1) gid=1000(user1) groups=1000(user1)
6.4 group模块:增加或删去组
group模块用法:
[root@nfs ~]# ansible-doc -s group
- name: Add or remove groups
group:
gid: # Op线程池原理tional `GID' to set fo线程池的七个参数r the group.是否运用自界说httpwatch的id号
name: # (required) Name of the group to女配每天都在抱大腿我要成仙 manage. 要处理的组名,必需求界说的。
state: # Whether the group should be present or not on the remote host. 状况信息,决定是删去仍是增加。创立:present,删去:absent
system: # If `yehttp协议s', indicates that the group created is a system group缓存. 是否创立体系用户
**示例:**创立一个体系组
[root@nfs ~女配满眼都是钱]# ansible np1.lxk.com -女配每天都在抱大腿我要成仙m group -a 'name=mygrp gid=200 system=yes'
np1.lxk.com | SUCCESS => {
"changed": true, #改动:成功
"gid": 200, #自界说组ID:200
"name": "mygrp", #组名:mygrp
"state缓存视频怎样下载到手机相册": "present"线程池原理, #状况:增加
"system": true #是否为体系用户:是
}
**示例:**删去组
[root@nfs ~]# ansible np1.lxk.com -m group -a 'name=女配没有求生欲晋江mygrp state=absent'
np1.lxk.com | SUCCESS => {
"changed": true,
"nahttp协议me": "mygrp",
"state": "absent"
}
上面指令重复履行时,changed状况为false。
[root@nfs ~]# ansible np1.lxk.com -m group -a 'name=mygrp state=absent'
np1.lxk.com | SUCCESS => {
"changedhttp 302": false,
"name": "mygrp",
"state": "absent"
}
6.5 user模块:处理用户帐户
模块内置指令一堆,请自行检查,根本见名知意。
**示例:**创立一个用户,姓名为tom,用户ID为2000,组名为mygrp,shell类型为/bin/bash,状况为增加。
[root@nfs ~]# ansible np1.lxk.com -m user -a 'name=tom state=present uid=2000 groups=mygrp shellNPM=/bihttpwatchn/bash'
np1.lxk.com | SUCCESS => {
"changed": true,
"comment": "",
"create_home": true,
"group": 2000,
"groups": "m线程池ygrp",
"home": "/home/tom",
"name": "tom线程和进程的差异是什么",
"shell"http 302: "/bin/bash",
"state": "presenthttp署理",
"system": false女配没有求生欲藤萝为枝,
"uid": 2000
}
**示例:**修改tom用户的ID为2020,shell类型为/bin/t缓存视频怎样转入本地视频csh
[root@nfs ~]# ansible np1.lxk.com -m user -a 'name=tom state=prese线程撕裂者nt uid=2020 groups=mygrp shell=/bhttps域名in/tcsh'
np1.lxk.com | SUCCESS => {
"append": f女配没有求生欲晋江alse,
"changed": true,
"comment": "",
"gr女配没有求生欲藤萝为枝oup": 2000,
"groups": "mygrp",线程的几种状况
"home": "/home/tom",
"move_home": false,
"nhttp://192.168.1.1登录ame": "tom",
"shell": "/bin/tcsh",
"state": "present",
"uid": 2020
}
6.线程池面试题6 copy模块
[root@nfs ~]# ansible-doc -s copy
- name: Copies files to remote locations #复制一个或多个文件至长途主机
copy:
dest: # (required) Remote absolute path where线程池面试题 the file shou缓存视频在手机哪里找ld be co线程是什么意思pied to. If `src' is a directory, this must be a directory too. If `dest女配没有求生欲藤萝为枝' is a nonexistent path and if eithttp 404her `deshttps安全问题t' ends with "/" ohttps和http的差异r `src' is a线程池原理 dirhttp 302ectory, `dest' is created. If `src缓存视频怎样下载到手机相册' an缓存视频怎样下载到手机相册d `dest' are files, tHTTPh女排名单e pa女排名单rent directory of `dest' isn't created: the task fails if it doesn't aHTTPSlready exist.
#复制指定文件至方针长途需求是肯缓存视频兼并app下载定途径。假定src是目录,dest也有必要是目录。假定dest是一个不存在的途径,并且dest不以/结束或许src是个目录,dest会自动创立。假定src和dest都是多个文件,dest的父目录没创立,复制就女排名单会失利。
src: # Local path to a file to copy to the remote server; can be absolu线程是什么意思te or relative.httpwatch If path is a directory, it is copied recursively. I线程池原理n this case, if path ends with "/", only inside女排名单 contents of that directory are copied to destination. Otherwise, if it does女配美炸天 not end with "/", thttp://192.168.1.1登录he directory itself with all contents is copied. This behavior is similar to Rsync.
#本线程撕裂者地需求复制到长途主机的文件的途径。可所以必定途径,也可所以相对途径。假定途径是个目录,则递归复制。假定途径以/https认证结束,只复制目录下的文件至方针女配美炸天途径。假定不http署理以/结束,则会把目录以及其下的内容都复制至方针主机。这种行为类似于rsync。
conten女配每天都在抱大腿我要成仙t: # When used instead of `src', sets the contents of a file directly to the specified value. For anything advance女配没有求生欲txtd or with formatt缓存视频兼并app下载ing also look at the template module.女配美炸天
#假定不运用src而运用content,把文件内容直接指定为content所指定的内容。然后剩余的懒得翻译了。
owner: # Name of the user tha女配没有求生欲txtt should own the file/directory, as would be fed to `chown'.
mode: # Mode the file or directory should be.
group: # Name of the group that should own the file/directory, as would be fed to `chown'.
**示例1:**经过co线程的几种状况nten线程和进程的差异是什么t指定文件内女配满眼都是钱容并复制至政线程撕裂者策主机(若不带n,不会自女配美炸天动换行)
[root@nfs ~]# ansible np2.lxk.com线程是什么意思 -m copy -a 'dest=/tmp/textfile.txt content="hello,brother!n"'
np2.lx女配没有求生欲藤萝为枝k.com | SUCCESS =>https协议 {
"changed": true,
"checksum": "8634f女配满眼都是钱f795ad950aa9c762c45cc8b07137248002a",
"dest": "/tmp/textfile.t缓存视频怎样转入相册xt",
"gid": 0,
"gr线程oup": "root",
"md5sum": "2252b10979e37d2884855线程池原理832666fd811",
"mode": "0644",
"oHTTPSwner": "root",
"sizeHTTPS": 15,
"src": "~None/.an线程池sible/tmp/ansible-tmp-1528471338.21-89043902941123/source", #ansible会把给定的HTTP源生成一个临时源作为源文件复制至方针方位。
"state": "file",
"uid": 0
}
方针https协议主机检查文线程安全件内容:线程撕裂者
[线程root@np2 ~]# cat /tmp/textfilehttps认证.txt
hello,brother!
**示例2:**复制本地/etc/fstab至np1.lxk.com的/tmp目录下,改名为fstab.txt,属主改为user2,权限0600.(user2需先创立)
[root@nfs ~]# np1.lxk.com all -m copy -a 'src=/etc/fstab dest=/thttp 302mp/fstab.txt owner=user2 mode=0600'
np1.lxk.com | SUC女配每天都在为国争光Chttps协议ESS => {
"changed": tru缓存视频兼并app下载e,
"checksum": "e634b64dbf499a1c2f14ade1dc9fc0d932b93093",
"dest": "/tmp/fstab.txt",
"gid": 0,
"group": "root",
"md5sum": "5aee64ae648da49b3b16e2b9ea70d27女配每天都在抱大腿我要成仙9",
"mode": "0600",
"owner": "user2",
"size"缓存的视频怎样保存到本地: 595,
"src": "~None/.ansible/tmp/ansible-tmp-1528518314.71-128514426299583/source",女排名单
"state": "file",
"uid": 1024
}
检查方针主机上的http协议文件:http署理
[root@np1 ~]# ll /tmp
total 4https域名
-rw------- 1 user2 root 595 Jun 9 12:25 fstab.txt
6.7 fetch模块
[root@nfs ~]# ansible-doc -s fetch
- name线程: Fet线程的几种状况ches a file from缓存视频在手机哪里找 remote nodes #从长途主机取来文件
fetch:
dest: # (required) A directory to save the file into.httpclient For example, if the `dest' directory is `/backup' a `src' file named `女排名单/etc/profile' on host缓存视频兼并app下载 `host.example.com', would be saved into `/backup/host.example.com/etc/profile'
#(有必要项)要保存文件的目录。如指定的目录为/backup,长途主机女配美炸天host.example.com上的线程池原理/etc/profile文件会保存在本地/backup/host.example.com/etc/profile
src: # (required) The file on the remote system to fetch. This `must' be a file, not a directory. Recursive fetching may be supported in a later release.
#长途主机需求fetch的文件,有必要是文件,不能是目录。往后可能会支撑目录。
**线程池创立的四种示例http署理1:**从长途主机np1.lxk.com上复制/etc/fstab至本地/tmp目录下
[rooHTTPSt@nf线程s ~]# ansible np1.lxk.com -m fetch -a 'src=/etc/fstab dest=/tmp/'
np1.lxk.co缓存视频怎样下载到手机相册m | SUCCESS => {
"changed": true,
"ch缓存数据能够铲除吗ecksum": "e634b64dbf499a1c2f14ade1dc9fc0d932b93093",
"dest":https和http的差异 "/tmp/np1.lxk.com/e缓存tc/fstab",
"md5sum": "5aee64ae648da49b3b16e2b9线程ea70d279",
"remote_checkhttp://192.168.1.1登录sum": "e634b64dbf499a1c2f14ade1dc9fc0d932b93093",
"remote_md5sum": null
}
**示例2:**从悉数可控的长途主机上复制/etc/fstab至本地/tmp目录下
[root@nfs ~]# ansible all -m fetch -a 'src=/etc/fstab dest=/tmp/'女配美炸天
np1.lxk.com | SUCCESS =女配每天都在抱大腿我要成仙> {
"女配没有求生欲txtchanged": fal线程和进程的差异是什么se,
"checksum": "e63缓存视频怎样转入相册4b64dbf499a1c2f缓存视频兼并14ade1dc9fc0d932b9https安全问题3093",httpclient
"dest": "/tmp/np1.lxk.com/etc/fstab",
"file": "/etc/fstab",
"md5sum": "5aee64ae648da49b3b16e2b9ea70d279"
}
np2.lxk.com | SUCCESS => {
"chhttp://www.baidu.comanged": true,
"checksum": "e634b64dbf499a1c2f14ade1dc9fc0d932b93093",
"dest": "/tmp/np2.lxk.com/etc/fstab",
"md5sum缓存视频怎样转入本地视频": "5aee64ae648da49b3b16e2b9ea70d279",
"remote_chttps和http的差异hecksum": "e634b64dbf499a1c2f14ade1dc9fc0d932b93093",
"remote_md5sum": null
}
nfs.lxk.com | SUCChttp 500ESS => {
"chahttps认证nged": true,
"checksum": "e634b64dbf499a1c2f14ade1dc9fc0d932b93093",
"dest": "/tmp/nfs.lxk.com/etc/fstab",
"md5shttps域名um": "5aee64ae648da49b3b16e2b9ea70d279",
"remote_checksum": "e634b64dbf499a1c2f14ade1dc9缓存视频怎样转入相册fc0d932b93093",
"remote_md5sum": null
}
检查本地目录:
[root@nfs ~]# tree /tmp
/线程撕裂者tmp
├── issue.txt
├── nfs.lxk.com
│ └── etc
│ └── fstab
├── np1.lxk.com
│ └── etc
│ └── fstab
└── np2.lxk.com
└──缓存数据能够铲除吗 etc
└── fstab
6 directories, 4 files
6.8 file模块:修改文件的特色信息
[root@nfs ~]# ansible-doc -s file
- na缓存视频怎样转入本地视频me: Sets attributes of files
file:
force: # force the creation of the symlinks in two cases: the source file doehttps和http的差异s not exist (but will appear later); the destination exists and is aNPM file (so, we need to unlink thehttps域名 "path" file and create symlin线程池原理k to the "src" file in place of it). #在两种状况下强制创立链接:源文件不存在(随后线程池面试题会呈现)或方针存在且是文件(将会吊销path指定的文件并创立链接)
group: # Name of the group that shoul线程是什么意思d own the file/directory, as would be fed to `chown'. #改动文件的属组
mode: # Mode the file or directory sho缓存视频怎样下载到手机相册uld be. For those used to `/usr/bin/chmod' remember that modes are actually octal numbers (like `0644' or `01777'). #改动文件或目录的权限
owhttpclientner: # Name of the user that should own the file/directory, as would be fed to `chown'. #改动文件的属主
path线程池原理: # (requihttpwatchred) path to the fihttps协议le being managed. Aliases: `dhttpclientest', `name' #有必要项。要修改的文件的途径
recurse: # recursively set t缓存视频怎样转入相册he specified file attributes (applies only to directories) #递归httpclient地设置文件特色
src: # path of the file to link thttp协议o (applies on缓存的视频怎样保存到本地ly to `state=link' and `state=hard'). Will accept absolute, relative and nonexisting paths. Relative paths a缓存视频怎样转入相册re not expanded.
#要链接到的文件途径(只适用于“state=link”和“state=hard”)。将承受必定途径、相对女配美炸天途径和不存在途径。相对途径没有打开。
state: #HTTP If `directory', all intermediate subdirectohttp://www.baidu.comries will be creathttps协议ed if they do not exist. Since Ansibhttp署理le 1.7 they will be created wi缓存视频变成本地视频th the supplied permissions. If `file', the file will NOT be created if it does not ex女配每天都在为国争光ist; see the `to线程池uc缓存视频怎样转入相册hhttp 404' value or the [copy] or [template] module if you want t线程池hat behavior. If `线程的几种状况link', the symb女配没有求生欲晋江olic linhttp 404k男配每天都在体内成果 will be created or changed. Use `https域名hard'缓存的视频怎样保存到本地 for hardlinks. If `absent', directories will be recursively delete缓存视频兼并d, and files or symlinks w线程池的七个参数ill be unlin线程安全kehttp://www.baidu.comd. Note that `absent' will not cause `file' to fail if the `path' does not缓存视频怎样转入本地视频 exi线程安全st as the state did not change. If `touch' (new in 1.4), an emhttps安全问题pty file will be created if the `path' does not exist, while an existi线程是什么意思ng file or directory will receive updated file access and modification times (si缓存视频怎样转入相册milar to the way `to女配满眼都是钱uch` works from the command line).
假定是目录,父目录不存在时会自动创立。
假定是文件缓存是什么意思,文件不存在时不线程是什么意思会创立。https认证
假定是链接,将会创立或许改动。
假定是absent,目录将会被递归删去,文件或链接会被吊销链接。
假定是touch,http://192.168.1.1登录不存在的文件将会被创立。目录将会更改访问时间和改动时间。
**示例线程的几种状况1:**修改np1.lxk.com主机/tmp/fstab.txt的属主为mygrp,权限为660
[root@nfs ~]# ansible np1.lxk.com -m file -a 'path=/tmp/fstab.txt group=mygrp mode=0660'
np1.lxk.com | SUCCESS => {
"changed": true,
"gid": 200,
"group": "mygrp",
"缓存视频变成本地视频mode": "0660",
"owner": "user2",
"path": "/tmp/fst缓存视频变成本地视频ab.txt",
"size": 595,
"state": "file",
"uid": 1024
}
检查方针主机文件特色:
[root@np1 ~]# ll -d /tmp/fstab.txt
-rw-rw---- 1 user2 mygrp 595 Jun 9 12:25 /tmp/fstab.HTTPStxt
**示例2:**为np1.lxk.com主机http://192.168.1.1登录的/tmp/fstab.txt创立软链接/tmp/fstab.link
[root@nfs ~]# ansible np1.lxk.com -m file -a 'path=/tmp/fstab.link src=/tmp/fstab.txt state=link'
np1.lxk.comhttp 404 | SUCCES女配没有求生欲晋江S => {
"changed": tru线程是什么意思e,
"dest": "/tmp/fstab.link",
"gid": 0,
"group":女配没有求生欲藤萝为枝 "root",
"mohttp 404de": "0777",
"owner": "rhttps认证oot",
"size": 14,
"src": "/tmp/fstab.txt",
"state": "link",
"uid": 0
}
**示例3:**在np1.lxk.com缓存视频怎样转入本地视频的/tmp目http协议录下创立目录file.d线程池创立的四种ir,权限为770
[root@nfs ~]# ansible nhttpclientp1.lxk.com -m file -a 'path=/tmp/file.dir mode=0770 state=directory'
np1.lxk.com | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0770",
"httpwatchowner": "root",
"pahttpclientth": "/tmp男配每天都在体内成果/file.dir",
"size": 4096,
"stahttps和http的差异te": "directory",
"uid": 0
}
6.9 get_url模块:下载文件
**示例:**下载一个文件至np1.lxk.com的/tmp目录下
[root@nfs ~]# ansible np1.lxk.com -m get_url -a 'dehttp 404st=/tmp/ url=男配每天都在体内成果https://mirrors.alihttp 404yun.com/centos/7.5.1804/pahttps和http的差异as/x86_64/openshift-origin36/jq-devel-1.5-1.el7.x86_64.rpm'
np1.l男配每天都在体内成果xk.com | SUCCESS => {
"changed": true,
"checksum_dest": null,
"chec女配没有求生欲k缓存视频在手机哪里找sum_src": "c566cb3df854f4551da1ab7f642e9HTTPS6889http协议b77439c",
"dest": "/tmp/jq-devel-1.5-1.缓存视频怎样下载到手机相册el7.x86_64.rpm",
"gid": 0,
"group": "root",
"md5sum": "43f5092eadb4855fb780e67244d997df",
"mode": "0644",
"msg": "OK (647httpclient2 bytes)女配没有求生欲",
"owner": "root",
"size": 6472,
"src": "/tmp/tmpwix52V",
"state": "file",
"status_code": 200,
"uid缓存": 0,
"url": "hthttpwatchtps://mirrors.aliyun.com/centos/7.5.HTTP1804/paas/x86_64/openshift-origin36/jq-dhttp 500evel-1.5-1.e线程l7.x86_64.rpm"
}
检查方针主机/tmhttps和http的差异p下的文件:
[root@https协议np1 ~]# ls /tmp
file.dir fstab.link fstab.txt jq-devel-1.5-1.el7.x86_64.rpm
6.线程10 cron模块:创立周期性计划使命
**示例1:**创立一个时间同步的使命,每5缓存视频变成本地视频分钟作业一缓存视频兼并次。
[root@nfs ~]# ansible np1.lxk.com -m cron -a "minute=*/5 job='/usr/sbin/ntpdate 19女排名单2.168.200.254 &> /dev/null' name=timesync"
np1.lxk.com | SUCCESS => {
"https域名changed": true,
"envs": [],
"jobs": [
"timesync"
]
}
方针主机上检查使命:
[root@np1 ~]# crontab -l
#Ansible: timesync #注明是由ansible生成的,标识名为timesync
*/5 * * * * /usr/sbin/ntpdate 192.168.200.线程254 &> /dev/null
**示例2:**删去方才创立的计划使命
ansible删去计划使命是依据name所界说的姓名来标识的。
[root@nfs ~]# ansible np1缓存的视频怎样保存到本地.lx线程池原理k.com -m cron -a "state=absent nam女排名单e=timesynhttp://192.168.1.1登录c"
np1.lxk.com | SUCChttps和http的差异ESS =&NPMgt; {
"changed": true,
"envs": [],
"jobs": []
}
检查方针主机计划使命列表为空。
6.11 yum模块:用yum包处http://192.168.1.1登录理器处理软件
[root@nfs ~]# ansible-doc -s yum
- name: Manages packages with the `yum' package mana线程撕裂者ger
yum:
conf_file: # The remote yumhttpclient configuration file to useHTTP for the transaction.
#指明其时事务运用哪个repo文件
state: # Whether to install (`present' or `installed', `latest'), or remove (`absent' or `removed') a线程池 packagehttpclient.
#设备选项:presetn、installed、latest
#卸载选项:absent、removed
name: # (requir女配每天都在抱大腿我要成仙ed) A package name , or package specifier with version, like `name-1.0'.
#有必要项。指定软件名
skip_broken: # Resolve depsolve pr女配美炸天oblems by removing packages that are causing problems from the transaction.
#越过错误信息
update_only: # When using latest缓存视频怎样转入本地视频, only update installe缓存数据能够铲除吗d packages. Do not ihttp署理nstall packa缓存视频怎样转入本地视频ges. Hhttps和http的差异as an effect only if state is `latest'
#只晋级,假女配没有求生欲藤萝为枝设软件包未设备则不设备。
**示例1:**设备或许检查nginx软件是否已设备
[root@nfs ~]# ansible all -m yum -a "name=nginx st女配每天都在抱大腿我要成仙ate=installe线程d"
nfs.lxk.com | SUCCESS => {NPM
"changed": false,
"msg": ""缓存视频变成本地视频,httpwatch
"rc": 0,
"女配没有求生欲results": [
"1:nginx-1.12.2-2.el7.x86_64 p女配没有求生欲晋江roviding nginx is already installed"
]
}
np1.lxk.com | SUCCESS => {
"changed": false,
"msg": "",
"r缓存的视频怎样保存到本地c": 0,
"results": [
"1:nginx-1.1线程安全2.2-2.el7.x86_64 providing nginx is already installed"
]
}
np2.lxk.com | SUCCESS =>缓存视频变成本地视频 {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"1:nginx-1.12.2-2.el7.x86_64 providing nginx is alr女配每天都在为国争光eady installed"
]
}
**缓存视频在手机哪里找示例2:**卸载nginx
[root@nfs ~]# ansible all -m yum女配没有求生欲txt -a "name=nginx s缓存是什么意思tate=absent"
nfs.lxk.com | SUCCESS => {
"changed": thttp协议rue,
"msg": "",
"rc"线程和进程的差异是什么: 0,
…………
太长,不贴了。在指令返回中能够看到Erasing字样,
…………
**示例3:**运用np1.lxk.com主机的/etc/yum.repos.d/repobak/base.repo设备httpd软件
[root@nfs ~]# ansible np1.lx缓存的视频怎样保存到本地k.com -m yum -a "name=ht缓存视频怎样转入本地视频tpd state=installed conf_file=/etc/yum.repos.d/repobak/base.repo"线程池
np1.lxk.com | SUCCESS => {
"changed": tru女配每天都在为国争光e,
"msg": "",
"rc": 0,
"results": [
"Resolving Dependenciesn--> Run缓存视频在手机哪里找ning transaction checkn---> Packa线程池创立的四种ge httpd.x86_64 0:2.4.6-80.el7.centos will be installedn--> Finished Dependency ResolutionnnDependencies Resolvednhttpwatchn=======================女配每天都在为国争光=========================================================n Package Arch Verhttp 500sion Repository Sizen=================================缓存的视频怎样保存到本地===============================================nInstalli线程池创立的四种ng:n httpd x8缓存的视频怎样保存到本地6_64 2.4.6-80.e女配美炸天l7.centos base 2.7 MnnTra女配每天都在抱大腿我要成仙nsaction Summaryn====线程撕裂者===============线程是什么意思====http署理=========================================================nInstall 1 PackagennTothttpcliental download size: 2.7 MnInstalled size: 9.4 MnDownloading packages:缓存视频兼并app下载nRunning thttp 302ransaction checknRunning transaction testnTransaction test succeedednRunning transacti缓存视频在手机哪里找onn Installing : httpd-2.4.6-80.el7.centos.x86_64 1线程和进程的差异是什么/1 n Verifyin女排名单g : httpd-2.4.6-8线程的几种状况0.el7.centos.x86线程的几种状况_64 1/1 nnInstalled:n httpd.x86_64 0:2.4.6-80.el7.centos nnComplete!n"
]
}女配每天都在为国争光
实践闪现作用就是这样。有点丑。但是设备成功了。
**示例4:**更新缓存并设备线程和进程的差异是什么httpd
[root@nfs ~]# ansible np2.lxk.com -m yum -女配每天都在抱大腿我要成仙a "name=httpd state=installed update_cache=yes"
np2.lxk.com | SUCCESS => {
"changed": false,
"msg": "",
"rchttps安全问题": 0,
"results"缓存的视频怎样保存到本地: [线程池的七个参数
"httpd-2.4.女配没有求生欲txt6-80.el7.cenHTTPtos.x86_64 providing httpd is already installed"
]
}
6.12 hostname模块:处理主机名,一般一次只能设置一个。
[root@nfs ~]# ansible-doc -s hostname
- name: Manage hostname
hostname:
name: # (required) Name of the host
示例:
[r缓存视频怎样转入本地视频oot@nfs ~]# ansible np1.lxhttps协议k.com -m hostname -a "name=np1"
np1.lxk.com | SUCCESS => {
"a缓存的视频怎样保存到本地nsible_factshttp://www.baidu.com": {
"ansible_线程池的七个参数domain": "lxk.co男配每天都在体内成果m",
"ansible_fqdn": "np1.lxk.com",
"ansible_hostname": "np1",
"ansible_nodename": "np1"
},
"changed": true,
"name": "np1http://www.baidu.com"
}
6.1http署理2 git模块
[ro线程池面试题ot@nfs ~]# ansible-doc -s git
- name: Deploy software (or files) from git ch女排名单eckouts
git:
clone: # If `no线程池创立的四种', do not clone the rehttp://www.baidu.compository if it d缓存数据能够铲除吗oes not exist locally
de女配每天都在为国争光st: # (required) The path of where the repository should be checked out. This parameter is required, unless `clone' is set to `no'.
r女配每天都在抱大腿我要成仙epo: # (required) git, SSH, or HTTP(S) protocol address of the git repository线程
version: # W缓存视频怎样下载到手机相册hat ve缓存视频在手机哪里找rsion of the repository to check out.
#指定要clone的版别,假定不指,默许为最新版别。
示例: 下载kuberne缓存tes至/tmphttps认证/kubernetes/缓存视频兼并app下载
[root@n线程撕裂者fs ~]# ansible np1.lxk.com -m git -a 'repo="https://gith线程安全ub.com/kubernetes/kubernethttp协议es.git" dest=/缓存视频怎样转入本地视频tmp/kubernetes'
#下载需求等候
检查方针主机下载状况:
[root@np1 ~]# tree -a /t线程池创立的四种mp/kubernetes
/tmp/kuberHTTPnetes
└── .git
├── branches
├── config
├── description
├── HEAD
├─缓存是什么意思─ hooks
│ ├── applyp女配美炸天atch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── phttp 404repare-commit-msg.sample
│ ├── pre-p女配美炸天ush.sample
│ ├── pre-rebase.sample
│ └── update.女配每天都在为国争光sample
├── i女排名单nfo
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── taghttpclients
10 directories, 13 f线程和进程的差异是什么iles
[root@np1 ~]# d女配美炸天u -sh /tmp/kubernetes
100K /tmp/kubernetes
#可看到目女配没有求生欲录已创立,因下载缓存是什么意思速度慢,文件仍是这么小。
6.13 pip模块:Manages Python library dependencies
[root@nfs ~]# ansible-doc -s pip
- name: Manages Pyhttps认证th女配满眼都是钱on library dependencies
pip:
name: # The name of a Python libraryHTTP to install缓存 or the url of the remote package. As of 2.2 you can supply a list of names.
#指定称谓,也能够以URL指定。2.2版别后支撑称谓列表。
state: # The state of modu线程池的七个参数le The 'forcereinstall' option is only available i缓存视频兼并n Ansible 2.1 and above.
#同yum的state
version: # The version number to install of the Python library specified in the `name' parameter.
#指定要设备的版别
6.14 npm模块:Manage node.js packages with npm
[root@nfs ~]# ansible-doc -s npm
- name: Manage node.js缓存视频在手机哪里找 packages with npmhttps协议
npm:
name: # The name of a node.js l缓存是什么意思ibrary to install
#要设备的node.js称谓
path: # The base path wherhttps和http的差异e to install the node.js libraries
#指明设备源地址
s女配没有求生欲晋江tate: # The state of the node.js library
version: # The version to bNPMe installed
6.15 service模块:处理服务
[roothttpclient@nfs ~]# ansible-doc -s service
- name: Ma女配每天都在抱大腿我要成仙nage services
service:
arguments: # Additional arguments provided缓存视频在手机哪里找 on the command line
enabled: # Whether t女配每天都在抱大腿我要成仙he service should start on boot. *At least one of state and enabled are required.*
#设置服务是否开机自启线程池原理
name: # (required) Name of the service.
#有必要项。服务的称谓
pattern: # If the service does not respond to the status command, name a substring to look f女配没有求生欲txtor as would be found in the output of the `ps' command as a stanhttp协议d- in for a status result. If the string is found, the service will be assumed to be running.
runlevel: # For OpenRC init scripts (ex: Gentoo) only. The runlevel that t缓存视频怎样转入相册his service belongs to.
#作业等级
sleep: # If the s女配没有求生欲txtervice is bei女配没有求生欲晋江ng `restart缓存视频怎样转入相册ed' then sleep this many s女配没有求生欲藤萝为枝econds between the stop and start command. This helps thttp://192.168.1.1登录o workaround badly behavi女配每天都在为国争光ng init sc缓存ri缓存数据能够铲除吗pts that exit immediately after signaling a process to stop.
#假定服务是重启,这个选项设置服务关闭后睡眠多长时间再从头打开服务。
state: # `started'/女配没有求生欲晋江`stopped' are idempotent actions that will not run commands unless neces线程池面试题sary. `restarted' will always bounce the service. `reloaded' will always reload. *AtHTTP least one of state and e线程的几种状况nabled a缓存视频怎样下载到手机相册re required.* Note that reloaded will star缓存的视频怎样保存到本地t the s线程安全ervice if it is not alrea缓存的视频怎样保存到本地dy started, even if your chosen init shttp 500ystem wouldn't normally.
#started:打开服务
#stoped:关闭服务
#restarted:重启服务
#reloaded:重载服务
#r女配没有求生欲txteloaded时,假定服务未发起会发起它。
**示例:**发起httpd服务,并设置开线程池面试题机自启
[root缓存视频变成本地视频@nfs ~]# ansible all -m service -a "name=httpd state=started enabled=yes"
nfs.lxk.com | SUCCESS => {
"change缓存视频在手机哪里找d": true,
"enabled": true,
"name":线程和进程的差异是什么 "httpd",
"state": "线程安全started",
"status": {
"Ac缓存视频怎样转入相册tiveEnterTimestampMonotonic": "0",
"ActiveEx女配满眼都是钱itTimestamhttps域名pMonotonic": "0",
"ActiveState":http://192.168.1.1登录 "inactiNPMve",
"After": "remote-fs.target basic.target nhttpwatchetwork.target nss-lookup.target tmp.mount sy缓存视频兼并stem.slice -.mount systemd-journald.socket",
"AllowIsolate": "no",
"AmbientCapabilities": "0",
…………
太长,不复制了
…………
检查悉数节点服务状况:
[root@nfs ~]# ansible all -m shehttp署理ll -a "ss线程池面试题 -tnlp | grep 80"
np1.lxk.com | SUCCESS | rc=0 &ghttps和http的差异t;>
LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=8077,fd=4))
LISTEN 0 128 :::80 :::* users:(("httphttps和http的差异d",pid=14265,fd=4),("httpd",pid=14264,fd=4),("httpd",pid=14263,fd=4),("httpd",pid=14262,fd=4),("httpd",pi女配没有求生欲晋江d=14261,fd=4线程池面试题),("httpd",pid=14260,fd=4))
np2.lxk.com | SUCCESS | rc=0 >>
LISTEN 0 128 :::80 :::* users:(("httpd",pid=14845,fd=4),("httpd",pidhttpclient=14844,fd=4),("ht缓存tpd",pid=14842,fd=4),("httpd",缓存是什么意思pid=14841,fd=4),("httpd",pid=14840,fd缓存视频在手机哪里找=4),("httpd",phttp://192.168.1.1登录id=14838,fd=4))
nfs.lxk.com | SUCCESS | rc=0 >>
LISTEN 0 128 :::80 :::* users:(("httpd",pid=6953,fd=4),("httpd",pid=6952,fd=4),("httpd",pid=6951,fd=4),("httpd",pid=6950,fd=4),("httpd",pid=6949,fd=4),("httpd",https协议pid=6948,fd=4))
[root@nfs ~]# ansible all -m shell -a "systemctl is-enabled htHTTPStpd"
np2.lxk.com | SUCCESS | rc=0 >>
enabled
np1.lxk.com | SUCCESS | rc=0 >>
enabled
nfs.lxk.com | SUCCESS |线程的几种状况 rc=0 >&g线程t;
enabled
#悉数节点httpd服务都HTTPS是开机自启
6.16 setup模块:获得方针主机的facts
用法:
[root@nfs ansible_workshop]# ansible np1.lxk.com -m setup
运用se线程和进程的差异是什么tup模块获取到的线程是什么意思悉数主机的facts都可在yaml文件中当作variables直接调用,若fatcs是嵌套女配没有求生欲txt的,能够用点号离隔引用。
6.17 thttpwatchemplate模板:
类似于copy模块
[root缓存视频兼并@nfs ansible_workshop]# ansible-doc -s template
- name: Template线程s a file out to a remote ser线程池面试题ver
template:
src: # (required) Path o线程池f a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path.
# 有必要项,源为Jinja缓存视频怎样下载到手机相册2格局的模板
dest: # (required) Location to r女配没有求生欲晋江ender the temp线程安全lahttps认证te to on the remote machine. # 有http://www.baidu.com必要https协议项,长途主机上存放模板的方位
group: # Name of the group that should own the file/direcNPMtory, as would be fed to线程撕裂者 `chown'.
# 应该具有文件/目录的组的称谓,此处指定的称谓将被发送到“ch女配没有求生欲藤萝为枝own”httpclient。
owner: # Name of the user that should own the file/directorhttps域名y, as would be fed to `chown'.
#应该具有该文件/目录的用户的称谓,此处指定的称谓将被发送到“chown”。
mode: # Mode the file or线程池创立的四种 directory should be. For those used to `/usr/bin/chmod' remember that modes are actually octal number女配满眼都是钱s (like `0644' or `01777'). # 文件或目录的权限。格局为`0644' 或 `01777'