Ansible 常用模块

[TOC]

文件管理模块

copy 模块

# 强制覆盖(默认),备份源文件,更改用户为 tomcat,组为tomcat,属性为 0644
ansible A -m copy -a 'src=/root/test.txt dest=/root force=yes backup=yes owner=tomcat group=tomcat mode=0644'
# 生成文件
ansible A -m copy -a 'content="aaa\bbb\t" dest=/root/test.txt2'

file 模块

# 创建目录时,将 state 的值设置为 directory
# 创建文件时,将 state 的值设置为 touch
# 创建软链接时,将 state 设置为 link
# 创建硬链接时,将 state 设置为 hard
# 删除文件时(不用区分目标是文件、目录、链接),将 state 设置为 absent

# 创建目录
ansible A -m file -a 'path=/root/test state=directory owner=nobody group=nogroup recurse=yes'
# 创建软连接
ansible A -m file -a 'path=/root/soft-link state=link src=/bin/bash'
# 删除文件
ansible A -m file -a 'path=/root/test state=absent'

blockinfile 模块

lineinfile 模块

find 模块

replace 模块

命令模块

command 模块

shell 模块

script 模块

系统模块

cron 模块

service 模块

user 模块

group 模块

包管理模块

yum_repository 模块

apt_repository 模块

yum 模块

apt 模块

文件操作

命令模块

系统模块

包管理模块

Last updated

Was this helpful?