编辑 hosts 配置文件
[root@mo ~]# vim /etc/ansible/hosts
创建目录
[root@mo ~]# mkdir /etc/ansible/playbook
编辑配置文件
[root@mo ~]# vim /etc/ansible/playbook/nginx.yml
执行测试
[root@mo ~]# ansible-playbook /etc/ansible/playbook/nginx.yml
roles
修改组
[root@mo ~]# vim /etc/ansible/hosts
检查主机 s 是否可连接
[root@mo ~]# ansible s -m ping
s0 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
s1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
创建 roles 的目录结构
[root@mo ~]# cd /etc/ansible/roles/
[root@mo roles]# mkdir nginx
[root@mo roles]# ls
nginx
[root@mo roles]# cd nginx/
[root@mo nginx]# mkdir
运行
[root@mo ~]# ansible-playbook /etc/ansible/playbook/test002.yml
卸载 nginx
[root@mo ~]# ansible s -m yum -a 'name=nginx state=absent'
编辑配置文件 --- 安装 nginx
[root@mo ~]# vim /etc/ansible/roles/nginx/tasks/main.yml
运行
[root@mo ~]# ansible-playbook /etc/ansible/playbook/test002.yml
使用 role 实现 lnmp
nginx 改配置 8080
mariadbz 中创建 eleme 数据库
创建表 ser
[root@mo ~]# vim /etc/ansible/roles/nginx/tasks/main.yml
[root@mo ~]# cd /etc/ansible/
[root@mo ansible]# mkdir script
[root@mo script]# vim dbtable.sh
[root@mo script]# cd
[root@mo ~]# vim /etc/ansible/playbook/test003.yml
[root@mo ~]# ansible-playbook /etc/ansible/playbook/test003.yml