ansible常用模块使用

2018-12-20 23:03

1、重启远程主机的服务:

eg: ansible remote -m service -a \

2、复制内容到远程主机的文件中:

eg: ansible remote -m copy -a 'content=\’

3、将远程主机的文件复制到本地主机

eg : ansible remote -mfetch–a“src=/tmp/somefile dest=/tmp/fetched”

4、用正则表达式匹配远程主机的文件内容,并对匹配到的一行内容做增删改操作: eg :ansible remote -mlineinfile–a “ dest=/etc/sudoers state=absent regexp=\”

5、用正则表达式匹配远程主机的文件内容,并对匹配到的字符串做替换操作:

eg :ansible remote -mreplace–a “dest=/etc/hosts regexp='(\\s+)old\\.host\\.name(\\s+.*)?$' replace='\\1new.host.name\\2' backup=yes”

6、使用playbook重启远程unbound服务 test.yml - - -

- hosts: remote remote_user: root tasks:

- name: restartunbound

service: name=unbound state=restarted

然后在命令行使用命令:ansible-playbook test.yml

7、一般使用handlers重启服务,这样一旦配置文件被修改成功,就触发重启模块 - name: template configuration file

template: src=template.j2 dest=/etc/foo.conf notify:

- restart memcached 这两个名字要一样的 - restart apache handlers:

- name: restart memcached service: name=memcached state=restarted - name: restart apache

service: name=apache state=restarted


ansible常用模块使用.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:全国2014年4月高等教育自学考试《中国行政史》试题.

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: