随笔分类 -  ansible

摘要:简介 该模块用于确保一个特定的行在一个文件中,或者使用一个正则表达式替换一个现有的行。 如果想要改变文件中相似的多行,可以使用replace模块。如果想要插入/更新/删除一个行块,可以使用blockinfile模块。 模块参数 名称必选默认值可选值备注 backrefs no no yes/no 如 阅读全文
posted @ 2020-12-06 12:38 Oops!# 阅读(495) 评论(0) 推荐(0) 编辑
摘要:Ansible playbook中变量的定义与引用有很多种方法,这里在本地环境测试验证,并整理如下 测试环境: 使用自己的Mac笔记本上安装ansible作为控制服务器,VMware Fusion虚拟机上运行了一个Centos7的虚拟机(192.168.243.146)作为远程被控主机 测试用pla 阅读全文
posted @ 2020-08-24 17:16 Oops!# 阅读(1011) 评论(0) 推荐(0) 编辑
摘要:ansible playbook可以将多个命令组合来执行,但是很多时候我们需要接收服务器的反馈,所以debug模块就非常重要了。 模块说明 调试模块,用于在调试中输出信息 常用参数: msg:调试输出的消息 var:将某个任务执行的输出作为变量传递给debug模块,debug会直接将其打印输出 ve 阅读全文
posted @ 2020-08-24 16:59 Oops!# 阅读(599) 评论(0) 推荐(0) 编辑
摘要:Jinja2 is a modern and designer-friendly templating language for Python frameworks. It is fast, reliable and widely used for dynamic file generation b 阅读全文
posted @ 2020-08-24 14:29 Oops!# 阅读(463) 评论(0) 推荐(0) 编辑
摘要:在ansible的playbook中task之间的相互传递变量 register.yml - hosts: all gather_facts: no tasks: - name: register vars shell: hostname register: info - name: display 阅读全文
posted @ 2020-05-03 00:23 Oops!# 阅读(1142) 评论(0) 推荐(0) 编辑
摘要:So just did a lot of experimenting and found Works: when: inventory_hostname in groups['group'] Fails:when: inventory_hostname in {{ groups['group'] } 阅读全文
posted @ 2020-01-08 15:17 Oops!# 阅读(1940) 评论(0) 推荐(0) 编辑
摘要:实例二:handlers: 在notify中列出的操作为handler,比如之前配置了apache的配置文件,http.conf端口发生变化后,重新执行ansible-playbook后,查看远程的端口,并未发生变化。需要用到notify 引入变量: vars:在后面添加变量名,然后再引入变量,必须 阅读全文
posted @ 2020-01-06 23:10 Oops!# 阅读(723) 评论(0) 推荐(0) 编辑
摘要:首先创建一个shell脚本 然后把该脚本分发到各个机器上 ansible compass -m copy -a "src=/tmp/df.sh dest=/tmp/df.sh mode=0755" 最后是批量执行该shell脚本 ansible compass -m shell -a "/tmp/d 阅读全文
posted @ 2018-08-10 17:12 Oops!# 阅读(1502) 评论(0) 推荐(0) 编辑
摘要:There are two options that you can add to the [defaults] section of the ansible.cfg file that will control whether or not .retry files are created and 阅读全文
posted @ 2018-04-13 18:12 Oops!# 阅读(232) 评论(0) 推荐(0) 编辑
摘要:通过Ansible playbook 方式安装 ntp 执行结果: 阅读全文
posted @ 2018-03-19 18:03 Oops!# 阅读(1056) 评论(0) 推荐(0) 编辑
摘要:十一、Ansible中的同步模块(rsync) Synchronize模块 1 2 3 4 5 6 7 This is a wrapper around rsync. Of course you could just use the command action to call rsync your 阅读全文
posted @ 2018-02-28 16:24 Oops!# 阅读(2570) 评论(0) 推荐(0) 编辑
摘要:##############################Deploy ansible client shell######################## echo "start deploy ansible client shell" ansible_DIR="/data/sh/" rm -rf /data/sh/* if [ ! -e $ansible_DIR ];then ... 阅读全文
posted @ 2018-02-07 09:42 Oops!# 阅读(332) 评论(0) 推荐(0) 编辑
摘要:ansible pro_adservers -m command -a 'w' ansible pro_adservers -m command -a 'hostname' ansible pro_adservers -m command -a 'ifconfig' ansible pro_adse 阅读全文
posted @ 2018-01-25 14:46 Oops!# 阅读(272) 评论(0) 推荐(0) 编辑
摘要:Ansible 安装 只需要在ansible 服务器上安装 yum install -y epel-release yum install -y ansible 服务器生成密钥对 ssh-keygen -t rsa 直接回车即可,不用设置密钥密码 把公钥(id_rsa.pub)内容放到对方客户端机器 阅读全文
posted @ 2018-01-17 16:24 Oops!# 阅读(3470) 评论(0) 推荐(0) 编辑
摘要:生产环境中大多时候是需要管理配置文件的,安装软件包只是在初始化环境的时候用一下。下面我们来写个管理nginx配置文件的playbook mkdir -p /etc/ansible/nginx_config/roles/{new,old}/{files,handlers,vars,tasks} 其中n 阅读全文
posted @ 2017-08-22 11:38 Oops!# 阅读(590) 评论(0) 推荐(0) 编辑
摘要:- hosts: testhost user: root gather_facts: True tasks: - name: use when shell: touch /tmp/when.txt when: facter_ipaddress == "172.7.15.106" Ansible pl 阅读全文
posted @ 2017-08-22 10:24 Oops!# 阅读(1097) 评论(0) 推荐(0) 编辑
摘要:ansible testhost -m copy -a "src=/etc/ansible dest=/tmp/ansibletest owner=root group=root mode=0755" 注意:源目录会放到目标目录下面去,如果目标指定的目录不存在,它会自动创建。如果拷贝的是文件,des 阅读全文
posted @ 2017-08-22 10:15 Oops!# 阅读(16425) 评论(0) 推荐(0) 编辑
摘要:不需要安装客户端,通过sshd去通信 基于模块工作,模块可以由任何语言开发 不仅支持命令行使用模块,也支持编写yaml格式的playbook 支持sudo 有提供UI(浏览器图形化)www.ansible.com/tower 10台主机以内免费 开源UI https://github.com/ala 阅读全文
posted @ 2017-08-22 10:06 Oops!# 阅读(327) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示