ansible base
https://www.cnblogs.com/franknihao/p/8565006.html
ansible facts
https://www.cnblogs.com/nineep/p/8984251.html
https://www.jianshu.com/p/c27f795094f1
facts redis
https://www.jianshu.com/p/a38017413b52
ansible templates
https://blog.csdn.net/weixin_44297303/article/details/103409673
ansible inventory
https://blog.csdn.net/weixin_34259559/article/details/89833466
https://blog.csdn.net/qq_34355232/article/details/82745414
---
- hosts: all
tasks:
- name: Install Nginx Package
yum: name=nginx state=present
- name: Copy Nginx.conf
template: src=./nginx.conf.j2 dest=/etc/nginx/nginx.conf owner=root group=root mode=0644 validate='nginx -t -c %s'
notify:
- Restart Nginx Service
handlers:
- name: Restart Nginx Service
service: name=nginx state=restarted
#第6行-第9行使用template模板去管理/etc/nginx/nginx.conf文件,owner,group定义该文件的属主及属组,使用validate参数指文件生成后使用nginx -t -c 检测配置文件语法,notify是触发handlers,如果同步后,文件md5值有变化的话会触发handler
#第10-12行定一个一个handler状态让Nginx去重启,
动态主机
ansible.cfg配置文件中的inventory配置项指向一个脚本
这个脚本有一定规范和参数要求
1.支持–list或者-l,这个参数运行后会显示所有的主机以及主机组的信息(JSON格式)
2.支持–host或者-H,这个参数后面需要指定一个host,运行结果会返回这台主机的所有信息(包括认证信息,主机变量等),也是json格式
#!/usr/bin/env python
# -*- coding=utf-8 -*-
# https://blog.csdn.net/qq_34355232/article/details/82745414
#########################
import argparse
import sys
import json
def lists():
r = dict()
h = ['172.17.42.10' + str(i) for i in range(1,4)]
hosts = {'hosts':h}
r['docker'] = hosts
return json.dumps(r,indent=4)
def hosts(name):
r = {'ansible_ssh_pass':'123456'}
cpis = dict(r.items())
return json.dumps(cpis,indent=4)
if __name__ == "__main__":
'''添加argparse的参数类实例,添加一些-l和-H的帮助显示提示'''
parser = argparse.ArgumentParser()
parser.add_argument('-l','--list',help='hosts list',action='store_true')
parser.add_argument('-H','--host',help='hosts vars')
'''vars方法把parser.parse_args()字典转换过去判断用户输入的内容'''
args = vars(parser.parse_args())
if args['list']:
print lists()
elif args['host']:
print hosts(args['host'])
else:
parser.print_help()
# 用实际主机来跑一批任务
# ansible -i hosts.py docker -m ping -k
ansible when
https://www.cnblogs.com/scajy/p/11561416.html
python-docx(.docx)
pip install -i http://pypi.douban.com/simple/ —trusted-host=pypi.douban.com/simple ipython
https://blog.csdn.net/zhouz92/article/details/107179616
https://www.cnblogs.com/gl1573/p/10114839.html