ansible模块lineinfile
示列:
sshd_set.yaml
---
- hosts: test
remote_user: root
gather_facts: False
tasks:
- name: set hostname
lineinfile: dest=/etc/sysconfig/network backrefs=yes regexp='^(HOSTNAME=).*' line='\1{{ inventory_hostname }}'
notify: reboot
handlers:
- name: reboot
shell: /sbin/reboot
iptables_add.yml
---
- hosts: test
gather_facts: false
tasks:
- name: iptables test
lineinfile: dest=/etc/sysconfig/iptables insertafter='^-A INPUT -i lo' line='-A INPUT -s 192.168.0.8 -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT'
notify: reload iptables
handlers:
- name: reload iptables
service: name=iptables state=reloaded
iptables_add.sh(iptables_add.yml的shell版)
#!/bin/bash line="\-A INPUT \-s 192.168.0.8 \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 10050 \-j ACCEPT"
iptables_conf="/etc/sysconfig/iptables" grep -s "$line" $iptables_conf
if [ $? != ];then
sed -i "/^-A INPUT -i lo/a $line" $iptables_conf
/etc/init.d/iptables reload
fi
说明:
ansible-doc lineinfile
替换 移除文件的单行 # 多行替换 移除参考replace模块
Options: (= is mandatory)(= 后面的参数是强制要有的)
- backrefs(default=no)
与state=present一起使用
一、支持反向引用
二、稍微改变了模块的操作方式
1、前插'insertbefore',后插'insertafter'失效
2、如果匹配到 替换最后一个匹配结果
3、如果未匹配到 不做任何改变
= dest
被编辑的文件
- insertafter
需要声明 state=present
在匹配行后插入,如果未匹配到则默认为EOF。ps:如果line存在则不会再插入,不管regexp有没有匹配到
- insertbefore
需要声明 state=present
在匹配行前插入,如果未匹配到则默认为BOF。ps:如果line存在则不会再插入,不管regexp有没有匹配到
- line
需要声明 state=present
插入或替换的字符串
- regexp
使用正则匹配
- state(default=present)
present 如果匹配到就替换(最后一个匹配结果) #如果未设置backrefs=yes 未匹配到也会在最后插入line
absent 移除匹配行(所有匹配到的)
ansible模块lineinfile的更多相关文章
- ansible 下lineinfile详细使用
ansible 下lineinfile详细使用 时间 2016-12-13 18:02:31 51CTO推荐博文 原文 http://zouqingyun.blog.51cto.com/78224 ...
- ansible 下lineinfile详细使用 【转】
转自 ansible 下lineinfile详细使用 - 散人 - 51CTO技术博客http://zouqingyun.blog.51cto.com/782246/1882367 一.简述 这几天在 ...
- ansible模块
ansible模块: 模块(Modules),类似于 "任务插件"("task plugins")或"库插件"("library ...
- ansible笔记(3):ansible模块的基本使用
ansible笔记():ansible模块的基本使用 在前文的基础上,我们已经知道,当我们使用ansible完成实际任务时,需要依靠ansible的各个模块,比如,我们想要去ping某主机,则需要使用 ...
- 第4天:Ansible模块
Ansible对远程服务器的实际操作实际是通过模块完成的,其工作原理如下: 1)将模块拷贝到远程服务器 2)执行模块定义的操做,完成对服务器的修改 3)在远程服务器中删除模块 需要说明的是,Ansib ...
- ansible模块command、shell、raw、script
简介 环境: ansible端: ip:192.168.100.129 hostname:node1.lansgg.com client端: ip:192.168.100.131 hostname:v ...
- win10的pycharm中安装ansible模块过程
前面的安装报错信息 ansible模块安装报错:Could not install packages due to an OSError: [Errno 2] No such file or dire ...
- ansible 模块 分享
A a10_server 管理A10 Networks AX / SoftAX / Thunder / vThunder设备 a10_service_group 管理A10网络设备的服务组 a10_v ...
- ansible模块文件操作
Ansible常用模块文件操作 [root@tiandong etc]# ansible-doc -l 列出ansible所支持的模块 [root@tiandong ~]# ansible-doc ...
随机推荐
- 链路层的简介和MTU
链路层杂谈(凭个人理解瞎说的,欢迎拍砖) 链路层,说白了就是把网络层的IP数据处理一下,加点东西,放到物理层上去. 加的东西:源.目的地址和CRC校验值,有的还有类型这个字段,用来区分协议. ...
- weblogic.nodemanager.common.ConfigException: Native version is enabled but nodemanager native library could not be loaded 解决办法
近日在一个原本工作正常的weblogic web server(操作系统为redhat 64位系统)上折腾安装redis/hadoop等东东,yum install了一堆第3方类库后,重启weblog ...
- jboss:跟踪所有sql语句及sql参数
默认情况下,hibernate/JPA 在server.log中记录的SQL语句,参数都是用?代替的,这样不太方便. 网上留传的p6spy在最新的jboss上(EAP 6.0+版本)貌似已经不起作用了 ...
- TinyFrame续篇:整合Spring IOC实现依赖注入
上一篇主要讲解了如何搭建基于CodeFirst的ORM,并且在章节末我们获取了上下文对象的实例:BookContext.这节主要承接上一篇,来讲解如何整合Spring IOC容器实现控制反转,依赖注入 ...
- 前后端分离工具之ftl-server
文章来源:https://www.npmjs.com/package/ftl-server 源代码可参考:https://github.com/szmtcjm/ftl-server/blob/mast ...
- ThreadLocal原理及其实际应用
前言 java猿在面试中,经常会被问到1个问题: java实现同步有哪几种方式? 大家一般都会回答使用synchronized, 那么还有其他方式吗? 答案是肯定的, 另外一种方式也就是本文要说的Th ...
- Windows Phone 8 显示当前项目的使用内存,最大峰值,最大内存上限
public static class MemoryDiagnosticsHelper { public static bool isStart = false; static Popup popup ...
- AutoMapperHelper
/// <summary> /// AutoMapper帮助类 /// </summary> public static class AutoMapperHelper { // ...
- 51-du 显示关于目录层次结构或文件磁盘使用情况的信息
显示关于目录层次结构或文件磁盘使用情况的信息 du [options] [path-list] 参数 不带任何参数的du将显示工作目录及其子目录磁盘使用情况的信息,path-list指定要获取磁盘占用 ...
- 53-whereis 查找文件
查找文件 whereis [options] file 参数 file 是whereis需要查找的文件,这些文件属于原始代码,二进制文件或是帮助文件 选项 -b 只查找二进 ...