ansible简单配置

ansible node1,node2,node3 --list-hosts : 列出匹配到的主机

在/ect/ansible/hosts里面加入主机清单,在组外面的是单台主机,分组控制比较方便,用ansible命令发送指令

node6 : 不属于任何组需要写在主机清单最上面

组名

node1

node2

node3

组名

node4

node5

ansible all --list-hosts : 查看匹配到的主机清单

ansible ungrouped --list-hosts : 查看不属于任何组的主机

db:children\] : 嵌套组 组名1 组名2 ansible ???.example.com --list-hosts : 列出任何三个开头的主机 ansible '\*.example.com' --list-hosts : 列出任何开头的主机 ansible '\*.example.com,!\*.lab.example.com' --list-hosts : 列出除了所有开头的.lab.example.com的.example.com 的主机 ansible 'prod,172\*,\*lab\*' --list-hosts : 列出prod组里的172开头的或包含lab的主机 ansible 'db,\&london' --list-hosts : 匹配到属于db组和london组的主机 ansible all --limit db1.example.com --list-hosts : 执行失败的主机指定在db1.example.com上再执行 ansible all --limit @hosts.txt --list-hosts : 把执行失败的主机在再执行一遍,必须要在主机清单中 ansible all -i hosts.txt --list-hosts : 把执行失败的主机在再执行一遍,不必非要在主机清单中 ansible node1 -m shell -a 'pwd' -u admin -k : 指定被控端用户admin ansible配置文件/etc/ansible/ansible.cfg remote_user = devop : 指定被控端连接的用户 \[privilege_escalation

become=True : 是否要提权

become_method=sudo : 用到sudo提权

become_user=root : 提权到root身份

become_ask_pass : 提权时,是否交互提示密码验证

定义ansible的配置文件

vim /etc/ansible/ansible.cfg

inventory = /etc/ansible/inventory #定义主机清单的路径

#remote_tmp = ~/.ansible/tmp #定义被控端的脚本临时存放目录

#local_tmp = ~/.ansible/tmp #定义主控端的脚本临时存放目录

forks = 5 #定义并发数

remote_user = devops #指定被控端连接的用户

ask_pass = True #密码密钥,默认时密钥验证

remote_port = 22 #被控端主机的端口号

host_key_checking = False #自动接受被控端的公钥

privilege_escalation

become=True #是否要提权

become_method=sudo #用sudo提权

become_user=root #提权到root用户

become_ask_pass=False #提权时不需要输入密码

#定义ansible的配置文件的优先级

1.ANSIBLE_CONFIG定义的配置文件路径,优先级最高

ANSIBLE_CONFIG=/var/lib/ansible/ansible.cfg

2.其次是当前目录下面的ansible.cfg

./ansible.cfg

3.其次是~/.ansible.cfg

4.最后是/etc/ansible/ansible.cfg

#ansible帮助文档

1.ansible官方文档

2.ansible内置帮助

ansible-doc -l 查看所有的模块

ansible-doc 模块名 查找该模块的参数

相关推荐
风清再凯3 天前
自动化工具ansible,以及playbook剧本
运维·自动化·ansible
IT乌鸦坐飞机3 天前
ansible部署数据库服务随机启动并创建用户和设置用户有完全权限
数据库·ansible·centos7
遇见火星16 天前
如何使用Ansible一键部署MinIO集群?
ansible
粥周粥16 天前
ANSIBLE
ansible
码农101号16 天前
Linux中ansible模块补充和playbook讲解
linux·运维·ansible
码农101号16 天前
Linux的Ansible软件基础使用讲解和ssh远程连接
ansible
烟雨书信17 天前
ANSIBLE运维自动化管理端部署
运维·自动化·ansible
碎碎-li17 天前
ANSIBLE(运维自动化)
运维·自动化·ansible
@donshu@20 天前
Linux运维-ansible-python开发-获取inventroy信息
linux·运维·ansible
Kendra91923 天前
Ansible
ansible