ansible几个常用模块及参数的简单演示
file模块使用示例
[root@node1 ~]# ansible-doc -l | grep "^\<file\>" file Sets attributes of files [root@node1 ~]# ansible-doc -s file --> 查看模块特有的参数 [root@node1 ~]# ansible all -m file -a "path=/tmp/testansible state=directory" --> 在目标主机的/tmp目录下创建testansible目
copy模块使用示例
[root@node1 ~]# ansible all -m copy -a "src=/etc/issue dest=/tmp/testansible" --> 将/etc/issue 文件复制到 /tmp/testansible 目录下,文件名和源文件名同名 [root@node1 ~]# ansible all -m copy -a "content='hello world' dest=/tmp/testansible/first" --> 给定内容生成文件 即 /tmp/testansible/first 的文件内容为 "hello world"
yum模块使用示例
[root@node1 ~]# ansible all -m yum -a "name=httpd state=absent" --> 卸载httpd程序包 [root@node1 ~]# ansible all -m yum -a "name=httpd state=present" --> 安装httpd程序包
service模块使用示例
[root@node1 ~]# ansible all -m service -a "name=httpd state=started" -->启动httpd服务 [root@node1 ~]# ansible all -m service -a "name=httpd state=stopped" --> 停止httpd服务
获取目标主机上的facts变量(在使用yaml模板语言时,可直接进行引用)
[root@node1 ~]# ansible all -m setup
其他模块及其参数的使用方式和上述的类似
读者可自行查看帮助即可
查看命令帮助的方法:
# ansible-doc -l # ansible-doc -s
转载于:https://blog.51cto.com/sixijie123/1878010