ansible – web百事通 https://www.askme-121.pw web互联网之家 Tue, 21 May 2024 13:05:44 +0000 zh-CN hourly 1 https://wordpress.org/?v=6.5.3 https://www.askme-121.pw/wp-content/uploads/2023/12/cropped-05ee702f-4b38-40f3-915f-c8fc68b10a91-32x32.png ansible – web百事通 https://www.askme-121.pw 32 32 ansible入门详解 https://www.askme-121.pw/ansible/ https://www.askme-121.pw/ansible/#respond Mon, 20 May 2024 05:17:56 +0000 https://www.askme-121.pw/?p=526 Ansible 是一个配置管理和应用部署工具,功能类似于目前业界的配置管理工具 Chef,Puppet,Saltstack。Ansible 通过 Python 语言开发,Ansible 默认通过 SSH 协议管理机器,所以 不需要在客户端安装程序,只需要将 Ansible 安装在一台服务器上,就可以去管理控制其它服务器了。不需要为它配置数据库,Ansible 不会以 daemons 方式来启动或保持运行状态。

一、ansible用法

1.1.安装ansible

yum -y install epel-release
yum -y install ansible

1.2.ansible参数选项

选项解释
-m指定要执行的模块,默认为command
-a指定模块的参数
-ussh连接的用户名,默认用root,ansible.cfg中可以配置
-b,–become相当于sudo
–become-usersudo到哪个用户,默认为root
-k提示输入sudo密码,当不是NOPASSWD模式时使用
-C只是测试一下会改变什么内容,不会真正去执行
-ffork多少进程并发处理,默认为5个
-i指定hosts文件路径,默认default=/etc/ansible/hosts
–list-host只打印有哪些主机会执行这个命令,不会实际执行
–private-key私钥路径
-Tssh连接超时时间,默认是10秒
-t日志输出到该目录,日志文件名以主机命名
-vvv显示详细日志

举例:

ansible all --list-host		#列出inventory定义的所有主机
ansible all -m ping -b --become-user root	#sudo到root执行ping模块

二、相关文件介绍

2.1.配置文件

/etc/ansible/ansible.cfg		#主配置文件
/etc/ansible/hosts				#主机清单
/etc/ansible/roles/				#存放角色目录

2.1.1. /etc/ansible/ansible.cfg解释

Ansible查找ansible.cfg文件的位置及顺序

1)ANSIBLE_CONFIG:首先,Ansible命令会检查环境变量,及这个环境变量将指向的配置文件
2)./ansible.cfg:其次,将会检查当前目录下的ansible.cfg配置文件
3)~/.ansible.cfg:再次,将会检查当前用户home目录下的.ansible.cfg配置文件
4)/etc/ansible/ansible.cfg:最后,将会检查在用软件包管理工具安装Ansible时自动产生的配置文件

inventory      = /etc/ansible/hosts		#存放主机清单文件
forks          = 5						#并发执行数量
poll_interval  = 15						#回频率或轮询间隔时间,单位s
sudo_user      = root					#远程主机sudo到什么用户,默认为root
ask_sudo_pass = True					#sudo时是否需要输入密码
ask_pass      = True					#执行ansible-playbook是否需要密码.默认为no
transport      = smart
remote_port    = 22						#远程主机端口号
module_lang    = C						#模块和系统之间通信的语言
module_set_locale = False
roles_path    = /etc/ansible/roles      #默认下载的Roles存放的目录
host_key_checking = False       		#首次连接是否需要检查key认证。设置为False,第一次连接远程主机不需要输入yes
timeout = 10            				#SSH超时时间
remote_user = root      				#连接到被控端机器的用户名,默认为root
log_path = /var/log/ansible.log     	#日志文件存放路径
executable = /bin/sh        			#执行的shell环境,用户shell模块
jinja2_extensions = jinja2.ext.do,jinja2.ext.i18    #允许开启jinja2扩展模块
private_key_file = /path/to/file    	#私钥文件存储位置
system_warnings = True      			#禁用系统运行Ansible潜在问题警告
deprecation_warnings = True    			#PlayBook输出禁用“不建议使用”警告
nocolor = 1         					#输出带上颜色区别,0表示开启,1表示关闭
pipelining = False      				#是否开启pipe SSH通道优化
gathering = explicit					#不收集系统信息,默认收集
[privilege_escalation]
become=True								#是否sudo
become_method=sudo						#sudo方式
become_user=root						#sudo后变为root用户
become_ask_pass=False					#sudo后不验证密码

2.1.2. /etc/ansible/hosts格式

[DB]					#表示DB组,下面的主机均属于该组
192.168.1.2
192.168.1.3
[fastdfs]
192.168.1.2
192.168.1.3  GROUP_NAME="g1"	#定义局部变量
192.168.1.4 ansible_ssh_user=ops ansible_ssh_port=22 ansible_become=true ansible_become_method=sudo	#ansible_become是否允许提权;ansible_become_method指定提权的方式
[k8s]
192.168.1.[4:10]		#[4:10]表示连续的主机,包含4和10
[webserver]
192.168.1.11:2222		#默认为22端口,如果不是,需指定
[linux_group:children]		#children是ansible内置变量,可以实现多个组的调用,linux_group是定义的组名
DB
k8s
[DB:vars]
mysql_port="3306"		#组变量
[all:vars]				#定义全局变量
db_master_ip="{{groups['DB'][0]}}"	#取DB组中的第一个IP			
ansible_ssh_user="devops"			

指定自定义主机清单文件

ansible -i myhost.ini --list-host

2.2.可执行文件

/usr/bin/ansible			#主程序
/usr/bin/ansible-doc		#查看文档
/usr/bin/ansible-galaxy		#连接https://galaxy.ansible.com/下载相应的roles
/usr/bin/ansible-playbook	#调用playbook剧本
/usr/bin/ansible-vault		#文件加密工具

三、配置基于root用户Key的验证

以root用户登录到主控端机器,ssh-keygen生成密钥对,通过ssh-copy-id 远程主机,将公钥拷贝到远程主机

四、ansible命令执行过程

  • 加载配置文件/etc/ansible/ansible.cfg
  • 加载模块文件,如command,ping
  • 通过ansible将模块或命令生成对应的临时py文件,并将该文件传输至远程服务器对应执行用户的$HOME/.ansible/tmp/ansible-tmp-数字 目录下,命名为XXX.PY文件
  • 给文件+x执行权限
  • 执行并返回结果
  • 删除临时py文件,退出

五、执行状态

绿色:执行成功并且不需要做改变的操作
黄色:执行成功并且对目标主机做变更
红色:执行失败

六、常用模块

ansible 192.168.1.2 -m ping -k		#测试主机是否可以通信;默认通过key验证,-k指定以用户名密码验证
ansible all -m ping			#检测主机清单文件中的所有主机
ansible db -m ping			#只检测db组内的主机
ansible *ser* -m ping		#支持通配符
ansible 'db:web' -m ping	#取db和web组的并集
ansible 'db:&web' -m ping	#取db和web组的交集
ansible 'db:!web' -m ping	#在db,不在web
ansible-doc -l				#列出所有模块
ansible-doc ping			#查看ping模块
ansible-doc -s ping			#简单了解ping模块
ansible all --list			#列出主机清单所有主机
ansible all -a 'ls /root'	#默认使用command模板,不支持变量、<、>、|、&、;等,需使用shell模块
ansible all -a 'creates=/ansible mkdir /ansible'	#不存在/ansible,则执行后面的mkdir
ansible all -a 'chdir=/root ls'		#切换到/root下执行ls

ansible all -m shell -a 'echo $HOSTNAME'
ansible all -m script -a '/etc/ansible/scripts/host.sh'	#会自动把主控端的脚本拷贝到被控端,并执行
ansible all -m copy -a 'src=/etc/hosts dest=/ansible/'	#拷贝本机文件到远程主机
ansible 192.168.119.134 -m copy -a "src=/etc/ansible dest=/tmp owner=root group=root mode=0755"	# 拷贝本机目录到远程客户端
ansible all -m copy -a 'content="hello world" dest=/ansible/f1'	#把content里面的内容写入到f1文件,会覆盖之前的内容
ansible all -m fetch -a 'src=/etc/hosts dest=files/ flat=yes'	#拷贝远程主机文件到当前路径的files/目录下;flat只拷贝hosts文件本身,不拷贝hosts文件所在的绝对路径

ansible all -m file -a 'path=/ansible/f2 state=touch'	#创建文件
ansible all -m file -a 'path=/ansible/f2 state=absent'	#删除文件
ansible all -m file -a 'path=/ansible/dir1 state=directory'	#创建目录
ansible all -m file -a 'src=/etc/hosts dest=/tmp/host state=link'	#创建软链接
ansible 10.93.62.156 -m hostname -a 'name=Master'		#修改主机名

ansible all -m cron -a 'minute=* weekday=2,4 job="/usr/bin/wall test warning" name=testcron'	#定时任务
ansible all -m cron -a 'disabled=true job="/usr/bin/wall test warning" name=testcron'		#取消定时任务
ansible all -m cron -a 'state=absent job="/usr/bin/wall test warning" name=testcron'		#删除定时任务

ansible all -m yum -a 'name=vsftpd update_cache=yes'		#yum装包,更新缓存
ansible all -m yum -a 'name=vsftpd state=removed'			#卸载包

ansible all -m user -a 'name=zhangsan shell=/bin/bash'		#创建用户

ansible web -m command -a "chdir=/tmp pwd"		#切换目录,执行命令

指定远程主机用户,并sudo到root用户
注意:需提前去远程主机配置允许普通用户sudo到root

echo "devops ALL=(ALL)  NOPASSWD: ALL" >> /etc/sudoers		#配置免密sudo
ansible all -a 'ls /root' -u devops -k -b	#-a指定命令;-u指定远程主机用户;-b执行sudo,默认sudo到root用户

七、ansible-galaxy

ansible-galaxy collection install nginxinc.nginx_core -c			#下载角色;-c忽略证书认证
ansible-galaxy list			#列出本机所有角色

八、ansible-vault

ansible-vault encrypt hello.yml		#加密yaml文件,需设置密码
ansible-vault view hello.yml		#查看yaml文件内容
ansible-vault edit hello.yml		#修改yaml文件内容
ansible-vault rekey hello.yml		#修改加密口令
ansible-vault decrypt hello.yml		#解密yaml文件

九、ansible-playbook

9.1.核心元素

hosts		#执行的远程主机列表
tasks		#任务集
templates	#模板
handlers	#也是task列表,和一般的task并没有什么区别.Handlers由通知者进行notify, 如果没有被notify,handlers不会执行.不管有多少个通知者进行了notify,等到 play 中的所有 task 执行完成之后,handlers 也只会被执行一次
tags		#打标签,通过标签调用特定的任务;多个任务可以共用一个标签
vars		#定义变量

9.2.playbook格式

---                      #习惯写法,区分不同的档案
# 创建文件
- hosts: db,myql         #选择hosts文件中的主机;可以选择多个主机,使用逗号分隔
  remote_user: root      #指定远程主机用什么用户执行
  gather_facts: no		 #收集远程主机信息,默认为yes

  tasks:                        #任务列表
    - name: create file         #任务说明
      file: path=/ansible/f2 state=touch  mode=0500      #使用file模块,创建文件;mode设置权限
    - name: test1
      shell: echo "{{ groups['mysql'][0] }}" >> /tmp/t1.txt		#获取[mysql]组的第一个成员
      
- hosts: redis:!redis[0]		#排除redis组的第一个成员
]]>
https://www.askme-121.pw/ansible/feed/ 0
自动化工具ansible安装和常用模块汇总 https://www.askme-121.pw/ansible-simple/ https://www.askme-121.pw/ansible-simple/#respond Wed, 15 May 2024 08:27:26 +0000 https://www.askme-121.pw/?p=521 ansible 是什么

Ansible 是一种 IT 自动化工具。它可以配置系统,部署软件以及协调更高级的 IT 任务,
例如持续部署,滚动更新。Ansible 适用于管理企业 IT 基础设施,从具有少数主机的小规
模到数千个实例的企业环境。Ansible 也是一种简单的自动化语言,可以完美地描述 IT 应
用程序基础结构。

ansible 的好处

简单易读:基于 YAML 文本编写,易于阅读,非专业的开发人员也可以编写。
功能强大:它可以用于管理配置,软件安装,流程自动化
无代理:不需要在客户端安装额外的 agent
跨平台支持:支持 linux,Windows,Unix 和网络设备

ansible 架构

  1. 控制节点(Control Node):控制节点是执行 Ansible 操作的主机。它通常是您的工作站或服务器,运行 Ansible 命令和管理配置的主机。
  2. 主机(Hosts):也称为目标节点,是您希望管理和配置的远程服务器或设备。Ansible 通过 SSH 连接到这些主机执行任务。
  3. Inventory(清单):清单是一个定义了 Ansible 将要管理的主机的文件。它可以包含主机的 IP 地址、主机名、组等信息。清单文件可以是静态的(手动编写)或者动态的(由脚本或其他工具生成)。
  4. Playbooks(剧本):Playbooks 是 Ansible 的核心概念之一,它们是用 YAML 格式编写的文件,用于描述一系列任务的执行。每个任务都描述了在目标主机上应该执行的操作,比如安装软件包、配置文件、启动服务等。
  5. 模块(Modules):模块是 Ansible 的工作单元,用于执行特定的任务。Ansible 提供了丰富的内置模块,可以用于系统管理、网络管理、云管理等各种场景。例如,”yum” 模块用于在基于 RPM 的系统上安装软件包,而 “copy” 模块用于复制文件到远程主机。

ansible 安装

主机端(master):192.168.7.42
被控端(node):192.168.7.99、192.168.7.217、192.168.7.42

在主机端安装

yum install -y epel-release
yum install -y ansible
#ansible配置文件:
/etc/ansible/ansible.cfg
/etc/ansible/hosts
生成秘钥:
ssh-keygen -t rsa  #在/root/.ssh/目录下生成秘钥
#被控端:(复制主机端公钥到被控端)
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.7.99  

或者

scp /root/.ssh/id_rsa.pub 192.168.7.99:/root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys

本机也要操作

ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.7.42

或者

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

测试

ssh 192.168.7.99 'ifconfig'
ssh 192.168.7.217 'ifconfig'

配置ansible 主机清单

cat /etc/ansible/hosts  //主机清单
[testhosts]   //按组分
192.168.7.42
192.168.7.99
192.168.7.217
[lbtest]
192.168.7.[42-45]   表示42-45内的ip

ansible -i <host_pattern> [-f forks] [-m module_name] [-a args]
  -i:指定主机清单的路径,默认为/etc/ansible/hosts(可省略)
  -m module:默认为command
  -f forks :默认为5个主机同时执行
例如:ansible testhosts -m command -a 'service salt-minion start'

ansible testhosts -u root -k -m shell -a ‘ps axu|grep salt’

备注:
-u 指定用户名
-k 指定密码
-m 指定模块
-a 指定参数

command不支持管道,此时可以用shell

使用children

cat /etc/ansible/hosts
[tests:children]   //定义子项
test1
test2
test3
[test1]
192.168.7.42
[test2]
192.168.7.99
[test3]
192.168.7.217

ansible支持主机列表的正则匹配

*/all 全量
: 逻辑或
& 逻辑与
! 逻辑非
[] 切片
~ 以~开头

如:
ansible all -m ping  #所有默认inventory文件中的机器
ansible "*" -m ping  #同上
ansible 121.28.13.* -m  ping #所有122.28.13.X机器

ansible  web1:web2  -m  ping  #所有属于组web1或属于web2的机器
ansible  web1:!web2  -m  ping #属于组web1,但不属于web2的机器
ansible  web1&web2  -m  ping  #属于组web1又属于web2的机器

ansible webserver[0]  -m  ping    #属于组webserver的第1台机器
ansible webserver[0:5]  -m  ping  #属于组webserver的第1到4台机器
ansible "~(beta|web)\.example\.(com|org)"  -m ping

ansible 常用模块

官方模块文档:https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html

下面是总结的我常用的模块

file:用于配置文件属性
script:用于在远程机器上执行本地脚本
yum:用于安装软件包
cron:配置计划任务
copy:复制文件到远程主机
command:在远程主机上执行命令,不支持管道
raw:类似于command模块,支持管道
user:配置用户
group:配置用户组
service:用于管理服务
ping:用于检测远程主机是否存活  如:ansible test1 -m ping
setup:查看远程主机的基本信息,获取到的主机信息,其中的KEY都可以在playbook中被当作变量引用  如: {{ ansible_all_ipv4_addresses }}
mount:配置挂载点
script 模块:用于在远程机器上执行本地脚本
script模块:在指定节点上执行/root/a.sh脚本(该脚本是在ansible控制节点上的)
fetch:从远程主机拉取文件到本地
archive模块用于压缩文件
unarchive模块用于解压文件
selinux:设置selinux防火墙
iptables:设置iptables防火墙
synchronize:使用rsync同步文件
get_url:主要用于从http、ftp、https服务器上下载文件(类似于wget)
filesystem:在块设备上创建文件系统

file模块

group:定义文件/目录的属组
owner:定义文件/目录的属主
mode:定义文件/目录的权限
path/name:必选项,定义文件/目录的路径
recurse:递归设置文件的属性,只对目录有效
state:定义文件状态
  - directory:如果目录不存在,创建目录
  - touch:如果文件不存在,创建一个新文件
  - absent:删除文件或目录
  - link:创建软连接
  - hard:创建硬链接(src指定要被链接的源文件路径,dest:被链接到的路径,只应用于state=link情况)
  - file:即使文件不存在,也不会被创建
示例:
    ansible test1 -m file -a "src=/etc/fstab dest=/tmp/fstab state=link"
    ansible test1 -m command  -a 'ls /tmp/ -lh'   
    ansible test -m file -a "name=/ane/soft  state=directory"
    ansible test1 -m file -a "path=/tmp/fstab state=absent" 
    ansible test1 -m file -a "path=/tmp/test state=touch"
    ansible test1 -m file -a 'path=/tmp/d1 state=directory owner=root group=root mode=755'   //创建目录
    ansible test1 -m command  -a 'path=/tmp/'
    ansible test1 -m file -a 'path=/tmp/d1 state=absent '   删除目录

command模块

creates:一个文件名,当该文件存在,则该命令不执行
free_form:要执行的linux指令
chdir:在执行指令之前,先切换到该指定的目录
ansible test2 -m command -a 'chdir=/ane   tar zcf 666.tar.gz 666.txt'
ansible test2 -m command -a 'ls -l /ane'
removes:一个文件名,当该文件不存在,则该选项不执行
示例:
 ansible test -a "/sbin/reboot"

yum模块

enablerepo:启用某个源
name:要进行操作的软件包的名字,也可以传递一个url或者一个本地的rpm包的路径
state:定义软件包状态
present:安装
absent:删除
latest:安装最新的
示例:
    ansible test -m yum -a 'name=httpd state=latest'
    ansible test -m yum -a 'name="@Development tools" state=present'
    ansible test -m yum -a 'name=http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present'

service模块

arguments:给命令行提供一些选项
enabled:是否开机启动  yes|no
name:必选项,服务名称
runlevel:运行级别
sleep:如果执行了restarted,在则stop和start之间沉睡几秒钟
state:对当前服务执行启动,停止、重启、重新加载等操作(started,stopped,restarted,reloaded)
示例:
ansible test -m service -a "name=httpd state=started enabled=yes"
ansible test -m service -a "name=foo pattern=/usr/bin/foo state=started"
ansible test -m service -a "name=network state=restarted args=eth0"

copy模块

src:源文件
dest:目标路径
backup:覆盖之前,是否备份原文件
owner:设定文件/目录的属主
group:设定文件/目录的属组
mode:设定文件/目录的权限
示例:
 ansible test -m copy -a "src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode=0644"
ansible test -m copy -a "src=/mine/ntp.conf dest=/etc/ntp.conf owner=root group=root mode=644 backup=yes"

cron模块

backup:对远程主机上的原任务计划内容修改之前做备份
day:日(1-31,*,*/2,……)
hour:小时(0-23,*,*/2,……)
minute:分钟(0-59,*,*/2,……)
month:月(1-12,*,*/2,……)
weekday:周(0-7,*,……)
job:要执行的任务,依赖于state=present
name:该任务的描述
special_time:指定什么时候执行,参数:reboot,yearly,annually,monthly,weekly,daily,hourly
state:确认该任务计划是创建还是删除(absent)
user:以哪个用户的身份执行
示例:
ansible test -m cron -a 'name="check dirs" hour="5,2" job="ls -alh > /dev/null"'
ansible test -m cron -a 'name="a job for reboot" special_time=reboot job="/some/job.sh"'

user模块

home:指定家目录,需要createhome为yes
groups:用户组
uid:用户UID
password:指定用户密码
name:用户名
createhome:是否创建家目录
system:是否创建为系统用户
remove:但state=absent时,删除家目录
state:创建或者删除
shell:指定用户shell环境

synchronize模块

#使用rsync同步文件,其参数如下:
archive: 归档,相当于同时开启recursive(递归)、links、perms、times、owner、group、-D选项都为yes ,默认该项为开启
checksum: 跳过检测sum值,默认关闭
compress:是否开启压缩
copy_links:复制链接文件,默认为no ,注意后面还有一个links参数
delete: 删除不存在的文件,默认no
dest:目录路径
dest_port:默认目录主机上的端口 ,默认是22,走的ssh协议
dirs:传速目录不进行递归,默认为no,即进行目录递归
rsync_opts:rsync参数部分
set_remote_user:主要用于/etc/ansible/hosts中定义或默认使用的用户与rsync使用的用户不同的情况
mode: push或pull 模块,push模的话,一般用于从本机向远程主机上传文件,pull 模式用于从远程主机上取文件
使用示例:
    src=some/relative/path dest=/some/absolute/path rsync_path="sudo rsync"
    src=some/relative/path dest=/some/absolute/path archive=no links=yes
    src=some/relative/path dest=/some/absolute/path checksum=yes times=no
    src=/tmp/helloworld dest=/var/www/helloword rsync_opts=--no-motd,--exclude=.git mode=pull

filesystem模块

在块设备上创建文件系统
选项: 
dev:目标块设备
force:在一个已有文件系统 的设备上强制创建
fstype:文件系统的类型
opts:传递给mkfs命令的选项
示例:
    ansible test -m filesystem -a 'fstype=ext2 dev=/dev/sdb1 force=yes'
    ansible test -m filesystem -a 'fstype=ext4 dev=/dev/sdb1 opts="-cc"'

mount模块

配置挂载点
选项: 
dump
fstype:必选项,挂载文件的类型 
name:必选项,挂载点 
opts:传递给mount命令的参数
src:必选项,要挂载的文件 
state:必选项 
present:只处理fstab中的配置 
absent:删除挂载点 
mounted:自动创建挂载点并挂载之 
umounted:卸载
示例:
    name=/mnt/dvd src=/dev/sr0 fstype=iso9660 opts=ro state=present
    name=/srv/disk src='LABEL=SOME_LABEL' state=present
    name=/home src='UUID=b3e48f45-f933-4c8e-a700-22a159ec9077' opts=noatime state=present
    ansible test -a 'dd if=/dev/zero of=/disk.img bs=4k count=1024'
    ansible test -a 'losetup /dev/loop0 /disk.img'
    ansible test -m filesystem 'fstype=ext4 force=yes opts=-F dev=/dev/loop0'
    ansible test -m mount 'name=/mnt src=/dev/loop0 fstype=ext4 state=mounted opts=rw'

get_url 模块

#该模块主要用于从http、ftp、https服务器上下载文件(类似于wget),主要有如下选项:
sha256sum:下载完成后进行sha256 check;
timeout:下载超时时间,默认10s
url:下载的URL
url_password、url_username:主要用于需要用户名密码进行验证的情况
use_proxy:是事使用代理,代理需事先在环境变更中定义
示例:
    get_url: url=http://example.com/path/file.conf dest=/etc/foo.conf mode=0440
    get_url: url=http://example.com/path/file.conf dest=/etc/foo.conf sha256sum=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c

archive模块

用于归档文件
path: /ane/soft下面是多路径的用法
  - /ane/soft
  - /ane/script/*
dest:
format: bz2、gz、tar、xz、zip
remove=yes 删除文件,默认为no
exclude_path 排除特定的目录
  - /path/to/foo/bar
  - /path/to/foo/baz
示例如下
- archive: 
  path=/ane/soft/nginx-1.8.1  
  dest=/ane/soft/nginx.tgz
  format=tar
  #remove=yes
- archive:
  path=/ane/script
  dest=/ane/script

unarchive模块

用于解压文件,模块包含如下选项:
copy:在解压文件之前,是否先将文件复制到远程主机,默认为yes。若为no,则要求目标主机上压缩包必须存在。
creates:指定一个文件名,当该文件存在时,则解压指令不执行
dest:远程主机上的一个路径,即文件解压的路径 
group:解压后的目录或文件的属组
list_files:如果为yes,则会列出压缩包里的文件,默认为no,2.0版本新增的选项
mode:解决后文件的权限
src:如果copy为yes,则需要指定压缩文件的源路径 
owner:解压后文件或目录的属主

示例如下:
- unarchive: src=foo.tgz dest=/var/lib/foo
- unarchive: src=/tmp/foo.zip dest=/usr/local/bin copy=no
- unarchive: src=https://example.com/example.zip dest=/usr/local/bin copy=no

selinux模块

开启selinux
 selinux: policy=targeted  state=enforcing
禁用selinux
 selinux: state:disabled
]]>
https://www.askme-121.pw/ansible-simple/feed/ 0