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 变更内网服务器配置的更多相关文章

  1. ansible 访问内网服务器

    ssh https://medium.com/@paulskarseth/ansible-bastion-host-proxycommand-e6946c945d30#.rauzlfv0z http: ...

  2. 搭建内网Yum源

    搭建内网yum源 阅读(2,238) 一:因内网服务器 众多,当统一安装一些比较大的rpm的时候全部从外网下载就比较慢,而且还占用了一定的出口流量,因此在内网部署了一台yum服务器,将阿里云的epel ...

  3. 内网环境使用ansible安装software 需要外网时,如何绑定代理呢

    内网环境使用ansible安装software 需要外网时,如何绑定代理呢? 方法一: 在ansible 的脚本里,yum install 的地方,添加语句: environment: https_p ...

  4. 【转】Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置

    Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置 原贴:https://www.cnblogs.com/jackadam/p/8568833.html ...

  5. (四)ansible 通过堡垒机访问内网服务器

    场景:     在ansible的使用过程中,存在这样的场景,ansible所在的管理节点与被管理的机器需要 通过一个跳板机才能连接,无法直接连接.要解决这个问题,并不需要在 ansible里做什么处 ...

  6. Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置

    简介: 无论办公.文件共享.团队协作还是家庭照片.视频.音乐.高清电影的存储,我们常常都有文件同步和存储的需求.但随着国内各大网盘的花式阵亡或限速,早已没什么好选择了.好吧,我已经转战使用onedri ...

  7. 使用阿里云服务器配置frp实现Windows系统RDP内网穿透

    1.frp服务器采用阿里云ecs的centos7.5系统,客户端是台windows10的系统,做一个RDP服务的内网穿透用. 2.首先下载frp到服务器(链接:https://github.com/f ...

  8. 企业内部在centos7.2系统中必杀技NTP时间服务器及内网服务器时间同步(windows和linux客户端同步)

    网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时UTC(Unive ...

  9. 烂泥:openvpn tun模式下客户端与内网机器通信

    本文由秀依林枫提供友情赞助,首发于烂泥行天下 前两篇文章我们介绍了有关openvpn的搭建与配置文件的讲解,这篇文章我们再聊介绍下,在tun模式下openvpn客户端如何与内网机器通信的问题. 一.实 ...

随机推荐

  1. PLSQL_性能优化系列15_Oracle Explain Plan解析计划解读

    2014-12-19 Created By BaoXinjian

  2. Java中类的加载、连接和初始化

    Java中类的加载.连接和初始化 类的加载.连接和初始化 先介绍一下JVM和类 JVM和类: 当我们调用Java命令运行某个Java程序时,该命令将会启动一个Java虚拟机进程,不管该Java程序有多 ...

  3. ylbtech-Unitity-CS:Indexers

    ylbtech-Unitity-CS:Indexers 1.A,效果图返回顶部   1.B,源代码返回顶部 1.B.1, // indexer.cs // 参数:indexer.txt using S ...

  4. MYSQL中replace into的用法以及与inset into的区别

    在向表中插入数据时,我们经常会遇到这样的情况:1.首先判断数据是否存在:2.如果不存在,则插入:3.如果存在,则更新. 在SQL Server中可以这样处理: if not exists (selec ...

  5. 将多个网页制作成一个CHM文件

    有时我们想将一个网站上的多个页面集中保存起来,在即使没有网络的情况下也能够查看. 这时可以将这些网页保存成.mht的单个文件(在IE中打开时,点击 文件 -> 另存) 再使用Easy CHM去将 ...

  6. win10安装软件被阻止后

    以管理员身份运行CMD,然后在cmd里执行就可以了.

  7. dede织梦列表页如何调用全站子栏目

    网站原代码:{dede:channel type='son'} <a href="[field:typelink/]">[field:typename/]</a& ...

  8. 90、 Android UI模板设计

    第一步:自定义xml属性 新建一个android项目,在values文件夹中新建一个atts.xml的文件,在这个xml文件中声明我们一会在使用自定义控件时候需要指明的属性.atts.xml < ...

  9. 有没有一行文件字过多后可以省略号显示,我说的不是用其他样式,BT本身有没有?谢谢

    .text-overflow {display: inline-block;max-width: 200px;overflow: hidden;text-overflow: ellipsis;whit ...

  10. 串口总是报'Error opening serial port'

    Comm1.CommName := '//./' + Trim(combx_Port.Text); 目前串口大于20  用上面方法解决的 网上也有上面方法解决如下错误的. 若是您已会应用SPCOMM且 ...