Ansible能够完成哪些任务python
Ansible特色mysql
Ansible安装方式web
python pip安装sql
优势shell
软件源安装ubuntu
优势安全
软件源安装(ubuntu)ssh
优势工具
Ansible配置学习
host配置
host文件: /etc/ansible/hosts
配置内容:
[test]
192.168.1.1
配置远程登陆
添加公钥:
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.1
连通测试
运行Ansible命令:
ansible all -m ping
正确的运行结果:
192.168.1.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
Ad-hoc怎么用
举例说明:
列出目标主机目录
ansible test -m shell -a "ls /root" --user=root
Ansible help message
Inventory是什么
Inventory主机组
[组名] 192.168.1.1 192.168.1.2
Inventory主机别名
jumper ansible_ssh_port = 22 ansible_ssh_host = 192.168.1.1
Inventory连接参数
ansible_ssh_host #将要链接的远程主机名,与你想要设定的主机别名不一样的话,可经过此变量设置 ansible_ssh_port #ssh端口号,若是不是默认的端口号,经过此变量设置 ansible_ssh_user #默认的ssh用户吗 ansible_ssh_pass #ssh密码(这种方式并不安全,咱们强烈建议使用 --ask-pass或SSH) ansible_sudo_pass #sudo密码(这种方式并不安全,咱们强烈建议使用 --ask-sudo-pass)
[websevers] www[01:50].example.com [databases] db-[a:f].example.com
实战
安装mysql
ansible test -m yum -a "name=mariadb-server state=latest" #安装使用yum模块 name参数是必须的,服务名称, state参数是可选的,latest表示安装
启动服务/暂停服务
ansible test -m systemd -a "name=mariadb state=started" #启动mariadb服务 ansible test -m systemd -a "name=mariadb state=stopped" #关闭mariadb服务
查看mysql服务是否启动
ansible test -m shell -a "ps -ef|grep mysql"