8.模块
8.1模块的分类
8.1.1 Core Module
(1)不须要格外下载和配置就能够直接使用的
(2)经常使用的module
(3)都是通过严格测试的
8.1.2 Extra Module
(1)Extra Module须要下载和配置才能使用
(2)次经常使用的
(3)还有可能存在bug的
注意:在ansible module文档上查看单个module的时候,每个module文档的底部都会标识,这是一个“Core Module”,或者这是一个“Extra Module”,好比yum就是一个core module,yum_repository就是一个extra module
8.2常见模块
可使用ansible-doc -l命令查看有哪些模块
使用ansible-doc -s copy命令能够查看模块的使用方法
8.2.1 command
(1)帮助:[root@pythion ~]# ansible-doc -s command
(2)简介:Command模块,命令模块、默认模块,用于在远程执行命令
(3)选项:
free_form:要执行的linux指令
chdir:在执行指令以前,先切换到该目录
removes:对应的文件不存在就执行command
creates:对应的文件存在就执行command
executable:切换shell来执行指令,该执行路径必须是一个绝对路径
(4)案例:远程查看时间和文件
[root@pythion ansible]# ansible zhang -m command -a "date"
[root@pythion ansible]# ansible all -m command -a "date"
[root@pythion ansible]# ansible wang -m command -a "date"
[root@pythion ansible]# ansible wang -m command -a "tail -1 /etc/passwd"
[root@pythion ansible]# ansible all -a "date"linux
8.2.2 cron
(1)简介:用来作计划任务
(2)state:
present:安装 默认为安装
absent:移除
若是须要移除的话,只须要写上name和absent就能够了
(3)案例:写入一个计划任务,查看是否已经成功写入。
须要注意的是不写的默认都是 ,名字得写,不写就会报错,状态默认是安装
[root@pythion ansible]# ansible zhang -m cron -a 'hour="/5" job="/bin/date" name="date test" state=present'
[root@pythion ansible]# ansible zhang -a "crontab -l"docker
8.2.3 user、group
(1)简介:实现用户帐号管理的
(2)案例:建立用户、建立组、建立组里边的成员
(3)注意:system 是不是系统组
[root@pythion ansible]# ansible all -m user -a 'name="user1" state=present' //建立用户
[root@pythion ~]# ansible zhang -m group -a 'name=pig gid=301 system=yes' //建立组
[root@pythion ~]# ansible zhang -m user -a 'name=pig uid=301 system=yes group=pig' //建立组里边的成员
ansible user 的passwd参数的值须要接受加密后的值
[root@dev2 test_deploy]# echo Zmc2tG1m= | openssl passwd -1 -stdin
$1$XI3TNbug$Y14rSXX7JxTtlTub9Car/0
tasks:shell
#直接传过去的
这个模块能够把压缩文件传输过去,而且传输过去以后解压的目录必须存在vim
#须要下载的tomcat
分为3种,远端目录有的就设置copy=no,默认为yes,而后若是要从网上下载在传送,写url便可
8.2.16 fetch模块
fetch模块能够把远端服务器的文件拉到本地,而且生成一个以主机名命名的
[root@zabbix-server ~]# ansible test -m fetch -a "src=/etc/fstab dest=/tmp/"
8.2.17 jenkis_job模块服务器
name: test
hosts: self
vars:
bianliang: ''
tasks:ide
name: echo love for vars
debug: msg='i love you'
when: ansible_os_family =="RedHatiiii"学习
[root@junmpserver etcd]# vim a.yml 测试
name: test
hosts: self
vars:
bianliang: ''
tasks:fetch
name: echo love for vars
debug: msg='i love you'
when: ansible_os_family =="RedHat"
name: Add jenkins job
hosts: jenkins
tasks:
name: Add jenkins job
jenkins_job:
name: '{{project}}'
password: 45ec4d09e9870fd9eea4b92787bb6068
url: http://114.55.227.11:8080
user: jenkins
config: "{{ lookup('template', '/root/playbook/jenkins/config.xml') }}"
8.2.22 wait_for模块
vars:
port: []