侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

ansible 常用模块命令记录

2023-12-17 星期日 / 0 评论 / 0 点赞 / 120 阅读 / 2184 字

1.copy 模块:把本地文件传输到指定路径;src 本地文件,dest目标文件。# 复制本地文件到指定路径[root@web1 ~]# ansible var -m copy -a "src=/ro

1.copy 模块:把本地文件传输到指定路径;src 本地文件,dest目标文件。

# 复制本地文件到指定路径[root@web1 ~]# ansible var -m copy -a "src=/root/test.log dest=/root/test.log.bak"

2.file 模块:文件操作(修改权限,新建目录等) state有如下参数 file,directory,link,hard,touch,absent

  • state=touch 新建文件
  • state=directory 新建目录
  • state=absent 删除
# 权限操作,文件须存在,[root@web1 ~]# ansible var -m file -a "dest=/root/a.txt mode=600 owner=mysql group=mysql"# state=directory 新建目录;类似 mkdir -p[root@web1 ~]# ansible var -m file -a "dest=/root/txt mode=600 owner=mysql group=mysql state=directory"# state=absent 删除[root@web1 ~]# ansible var -m file -a "dest=/root/a.txt state=absent"

3.user 模块,state只有present,absent两个参数

# 新建用户[root@web1 ~]# ansible all -m user -a "name=foo password=<crypted password here>"# 删除用户[root@web1 ~]# ansible all -m user -a "name=foo state=absent"

4.yum 模块 state有如下参数 absent,present,installed,removed,latest

# 安装[root@web1 ~]# ansible webservers -m yum -a "name=name state=present"#  yum install 指定版本[root@web1 ~]# ansible webservers -m yum -a "name=name1.5 state=present"#  yum install 最新版本[root@web1 ~]# ansible webservers -m yum -a "name=name state=latest"# yum remove [root@web1 ~]# ansible webservers -m yum -a "name=name state=removed"

5.server 模块有如下参数 running,started,stopped,restarted,reloaded

# 启动[root@web1 ~]# ansible webservers -m service -a "name=httpd state=started"# 重启[root@web1 ~]# ansible webservers -m service -a "name=httpd state=restarted"# 重载[root@web1 ~]# ansible webservers -m service -a "name=httpd state=reloaded"# 停止[root@web1 ~]# ansible webservers -m service -a "name=httpd state=stopped"

广告 广告

评论区