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 模块名 查找该模块的参数

相关推荐
梅孔立12 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
henry10101014 天前
Ansible自动化运维全攻略(AI生成)
linux·运维·python·ansible·devops
only_Klein18 天前
Ansible变量详解
运维·自动化·ansible
only_Klein18 天前
Ansible Roles 详解
自动化·ansible·role
only_Klein18 天前
Ansible 条件判断与流程控制详解
自动化·ansible
axPpcfNN18 天前
可直接编译运行 c#解析dxf可读取圆直线弧多段线源码-无封装缩放拖拽 可读取坐标信息 支持多...
ansible
Maggie_ssss_supp20 天前
Linux-ansible自动化运维
运维·自动化·ansible
迎仔20 天前
10-算力中心运维三剑客:Ansible + Jenkins + K8s 高效实战
运维·kubernetes·ansible·jenkins
识途老码21 天前
25.ansible的hostname模块
ansible·hostname
Cloud Traveler24 天前
Ansible+cpolar:NAS 远程自动化运维方案
ansible