[root@ansible ~]# yum -y install ansible
[root@ansible ~]# yum remove ansible
[root@ansible ~]# ansible-doc cron #查看cron模块详细帮助信息
[root@ansible ~]# ansible-doc -s cron #查看cron模块简要信息
[root@ansible ~]# ansible hostname|ip -m setup #获取ansible内置变量(内置变量调用方式:ansible_eth0.ipv4.address)
[root@ansible ~]# ansible-playbook -i /root/hosts.txt test.yaml #ansible执行自定义主机文件
#hosts.txt文件格式
192.168.1.2 ansible_ssh_user=root ansible_ssh_pass='PASSWORLD'
192.168.1.3 ansible_ssh_user=root ansible_ssh_pass='PASSWORLD'
[web]
192.168.1.2
[db]
192.168.1.3
[hosts:children]
web
db
#定义变量
[hosts:vars]
domain="www.test.com"
#test.yaml文件格式
- name: Initalize system
hosts: hosts
remote_user: root
gather_facts: True
roles:
- role: web
tags: init
解决ansible cryptography模块告警
[root@ansible ~]# ansible 127.0.0.1 -m ping
/usr/local/python2.7/lib/python2.7/site-packages/ansible-2.9.18-py2.7.egg/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
from cryptography.exceptions import InvalidSignature
[root@ansible ~]# pip2.7 install cryptography==2.9
参考链接:
https://blog.51cto.com/wujianwei/2082880 #ansible不配置ssh免密钥,使用密码登录
http://www.ansible.com.cn/docs/playbooks_intro.html #about-playbooks
https://www.cnblogs.com/yanjieli/p/10969299.html
https://www.cnblogs.com/coolops/p/12793640.html
https://www.likecs.com/show-40538.html
https://my.oschina.net/kangvcar/blog/1830155
https://github.com/openstack/kolla-ansible