ansible 变更内网服务器配置
https://serversforhackers.com/tag/ansible
http://docs.ansible.com/ansible/developing_api.html
https://github.com/linuxdynasty/ld-ansible-modules/blob/master/test/cloud/amazon/test_kinesis_stream.py
ansible.cfg
[defaults]
forks = 20
transport = ssh
host_key_checking = False
[ssh_connection]
ssh_args = -F /data/ansible/ssh_config
pipelining = true
change_link.yaml
---
- hosts: proxy
remote_user: ansible
become: yes
become_user: root
become_method: sudo
vars:
proxy_host: '58.215.39.12'
tasks:
- name: update /etc/hosts
template: src=templates/hosts.j2 dest=/etc/hosts owner=root group=root mode=0644
notify: restart dnsmasq
handlers:
- name: restart dnsmasq
service: name=dnsmasq state=restarted
templates/hosts.j2
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
{{ proxy_host }} proxy.live
ansible-playbook -i inventory change_link.yaml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [10.150.1.51]
ok: [10.150.1.52]
TASK [update /etc/hosts] *******************************************************
changed: [10.150.1.51]
changed: [10.150.1.52]
RUNNING HANDLER [restart dnsmasq] **********************************************
changed: [10.150.1.51]
changed: [10.150.1.52]
PLAY RECAP *********************************************************************
10.150.1.51 : ok=3 changed=2 unreachable=0 failed=0
10.150.1.52 : ok=3 changed=2 unreachable=0 failed=0
demo
from collections import namedtuple
from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager
from ansible.inventory import Inventory
from ansible.playbook.play import Play
from ansible.executor.task_queue_manager import TaskQueueManager
Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'become', 'become_method', 'become_user', 'check'])
# initialize needed objects
variable_manager = VariableManager()
loader = DataLoader()
options = Options(connection='local', module_path='/path/to/mymodules', forks=100, become=None, become_method=None, become_user=None, check=False)
passwords = dict(vault_pass='secret')
# create inventory and pass to var manager
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list='localhost')
variable_manager.set_inventory(inventory)
# create play with tasks
play_source = dict(
name = "Ansible Play",
hosts = 'localhost',
gather_facts = 'no',
tasks = [
dict(action=dict(module='shell', args='ls'), register='shell_out'),
dict(action=dict(module='debug', args=dict(msg='{{shell_out.stdout}}')))
]
)
play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
# actually run it
tqm = None
try:
tqm = TaskQueueManager(
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
options=options,
passwords=passwords,
stdout_callback='default',
)
result = tqm.run(play)
finally:
if tqm is not None:
tqm.cleanup()
ansible 变更内网服务器配置的更多相关文章
- ansible 访问内网服务器
ssh https://medium.com/@paulskarseth/ansible-bastion-host-proxycommand-e6946c945d30#.rauzlfv0z http: ...
- 搭建内网Yum源
搭建内网yum源 阅读(2,238) 一:因内网服务器 众多,当统一安装一些比较大的rpm的时候全部从外网下载就比较慢,而且还占用了一定的出口流量,因此在内网部署了一台yum服务器,将阿里云的epel ...
- 内网环境使用ansible安装software 需要外网时,如何绑定代理呢
内网环境使用ansible安装software 需要外网时,如何绑定代理呢? 方法一: 在ansible 的脚本里,yum install 的地方,添加语句: environment: https_p ...
- 【转】Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置
Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置 原贴:https://www.cnblogs.com/jackadam/p/8568833.html ...
- (四)ansible 通过堡垒机访问内网服务器
场景: 在ansible的使用过程中,存在这样的场景,ansible所在的管理节点与被管理的机器需要 通过一个跳板机才能连接,无法直接连接.要解决这个问题,并不需要在 ansible里做什么处 ...
- Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置
简介: 无论办公.文件共享.团队协作还是家庭照片.视频.音乐.高清电影的存储,我们常常都有文件同步和存储的需求.但随着国内各大网盘的花式阵亡或限速,早已没什么好选择了.好吧,我已经转战使用onedri ...
- 使用阿里云服务器配置frp实现Windows系统RDP内网穿透
1.frp服务器采用阿里云ecs的centos7.5系统,客户端是台windows10的系统,做一个RDP服务的内网穿透用. 2.首先下载frp到服务器(链接:https://github.com/f ...
- 企业内部在centos7.2系统中必杀技NTP时间服务器及内网服务器时间同步(windows和linux客户端同步)
网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时UTC(Unive ...
- 烂泥:openvpn tun模式下客户端与内网机器通信
本文由秀依林枫提供友情赞助,首发于烂泥行天下 前两篇文章我们介绍了有关openvpn的搭建与配置文件的讲解,这篇文章我们再聊介绍下,在tun模式下openvpn客户端如何与内网机器通信的问题. 一.实 ...
随机推荐
- Android流量统计TrafficStats类
对于Android流量统计来说在2.2版中新加入了TrafficStats类可以轻松获取,其实本身TrafficStats类也是读取Linux提供的文件对象系统类型的文本进行解析. android.n ...
- mat(Eclipse Memory Analyzer tool)之二--heap dump分析
文章中的shallow.retained关键字的说明见:GC是如何回收时的判断依据.shallow size.retained size 在本文中,将介绍MAT(Eclipse Memory Anal ...
- 深入ThreadLocal之三(ThreadLocal可能引起的内存泄露)
threadlocal里面使用了一个存在弱引用的map,当释放掉threadlocal的强引用以后,map里面的value却没有被回收.而这块value永远不会被访问到了. 所以存在着内存泄露. 最好 ...
- make[1]: *** [pcrecpp.lo] 错误 1
在安装:pcre-8.30 时,报如下错误: [root@localhost pcre-8.30]# make && make installmake all-ammake[1]: ...
- Protobuf从安装到配置整理帖
新做的Mini项目计划使用Google的Protobuf来做,关于Protobuf是什么玩意能干什么请自己去看这里:http://code.google.com/p/protobuf/ 这里讲一下安装 ...
- c#生成缩略图
publicstaticvoidGenThumbnail(Image imageFrom,stringpathImageTo,intwidth,intheight) { ...
- oracle10g如何配置客户端
http://jingyan.baidu.com/article/4d58d541c108939dd4e9c0f5.html 不行的话: 对tnsnames.ora进行编辑:ORCL = (DESCR ...
- C语言中的atan和atan2(转)
在C语言的math.h或C++中的cmath中有两个求反正切的函数atan(double x)与atan2(double y,double x) 他们返回的值是弧度 要转化为角度再自己处理下. 前者 ...
- 最小生成树之prim
prim是设置一个初始结点,寻找其周围最小的边权值,并将该结点作为初始结点,继续寻找现在结点周围的边权值的最小值,但要注意如果这次寻找的某个边权值没有上次的小的话仍然保留上一次的边权值,即lowcas ...
- Linux学习小结(转)
linux目录架构 / 根目录/bin 常用的命令 binary file 的目錄/boot 存放系统启动时必须读取的档案,包括核心 (kernel) 在内/boot/grub/menu.l ...