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

  1. ---
  2. - hosts: all
  3. tasks:
  4. - name: Install Nginx Package
  5. yum: name=nginx state=present
  6. - name: Copy Nginx.conf
  7. template: src=./nginx.conf.j2 dest=/etc/nginx/nginx.conf owner=root group=root mode=0644 validate='nginx -t -c %s'
  8. notify:
  9. - Restart Nginx Service
  10. handlers:
  11. - name: Restart Nginx Service
  12. service: name=nginx state=restarted
  13. #第6行-第9行使用template模板去管理/etc/nginx/nginx.conf文件,owner,group定义该文件的属主及属组,使用validate参数指文件生成后使用nginx -t -c 检测配置文件语法,notify是触发handlers,如果同步后,文件md5值有变化的话会触发handler
  14. #第10-12行定一个一个handler状态让Nginx去重启,

动态主机

ansible.cfg配置文件中的inventory配置项指向一个脚本
这个脚本有一定规范和参数要求
1.支持–list或者-l,这个参数运行后会显示所有的主机以及主机组的信息(JSON格式)
2.支持–host或者-H,这个参数后面需要指定一个host,运行结果会返回这台主机的所有信息(包括认证信息,主机变量等),也是json格式

  1. #!/usr/bin/env python
  2. # -*- coding=utf-8 -*-
  3. # https://blog.csdn.net/qq_34355232/article/details/82745414
  4. #########################
  5. import argparse
  6. import sys
  7. import json
  8. def lists():
  9. r = dict()
  10. h = ['172.17.42.10' + str(i) for i in range(1,4)]
  11. hosts = {'hosts':h}
  12. r['docker'] = hosts
  13. return json.dumps(r,indent=4)
  14. def hosts(name):
  15. r = {'ansible_ssh_pass':'123456'}
  16. cpis = dict(r.items())
  17. return json.dumps(cpis,indent=4)
  18. if __name__ == "__main__":
  19. '''添加argparse的参数类实例,添加一些-l和-H的帮助显示提示'''
  20. parser = argparse.ArgumentParser()
  21. parser.add_argument('-l','--list',help='hosts list',action='store_true')
  22. parser.add_argument('-H','--host',help='hosts vars')
  23. '''vars方法把parser.parse_args()字典转换过去判断用户输入的内容'''
  24. args = vars(parser.parse_args())
  25. if args['list']:
  26. print lists()
  27. elif args['host']:
  28. print hosts(args['host'])
  29. else:
  30. parser.print_help()
  31. # 用实际主机来跑一批任务
  32. # 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