ansible httpd

卸载服务
ansible all -m shell -a ‘yum -y remove nginx’

检查用户 组 uid gid
ansible all -m shell -a ‘getent passwd nginx’
ansible all -m shell -a ‘getent group nginx’

ansible all -m shell -a ‘getent passwd | grep 123’

删除用户
ansible all -m shell -a ‘userdel -r nginx’
ansible all -m user -a ‘name=apache state=absent’

验证
ansible all -m shell -a ‘ss -ntlpe’ /* 端口 */
ansible all -m shell -a ‘ps aux | grep nginx /* 用户 进程数 */

编译安装
一台机器编译好
安装目录 打包复制

ansible /* 任意文件夹 */

├── group_vars /* 变量 –> 所有 role */


├── File_role.yml /* 与 roles 平级 */
│ …


└── roles


├── Pro_1
│ │
│ ├── tasks /* 必须有 其他文件夹 可无 */
│ │ ├── main.yml
│ │ … /* File.yml */
│ │
│ ├── handlers
│ │ └── main.yml
│ ├── vars
│ │ └── main.yml
│ ├── templates
│ │ ├── File.j2
│ │ …
│ └── files
│ ├── File
│ …


└── Pro_2
├── …

mkdir -pv Pro_1/{tasks,templates,vars,handlers,files}

vim app_role.yml
– hosts: all
remote_user: root

roles:
– app

– Pro_2 /* 调用多个角色 */

– { role: httpd , tags: [‘web’,’httpd’] } /* 添加标签 */
– { role: nginx , tags: [‘web’,’nginx’] , when: ansible_distribution_major_version == “7” } /* 条件判断 */
ansible-playbook -C -t httpd app_role.yml /* 挑选 标签 执行 */

vim tasks/main.yml
– include: group.yml
– include: user.yml
– include: yum.yml
– include: templ.yml
– include: start.yml
– include: copyfile.yml

– include: roles/Pro_2/tasks/File.yml /* 调用其他角色中任务 copy路径问题…*/
vim group.yml
– name: create group
group: name=app system=yes gid=123
vim user.yml
– name: create user
user: name=app group=app system=yes shell=/sbin/nologin uid=123
vim yum.yml
– name: install package
yum: name=httpd
vim templ.yml
– name: copy conf
template: src=httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf /* File.j2 即可 */
notify: restart service
vim start.yml
– name: start service
service: name=httpd state=started enabled=yes
vim copyfile.yml
– name: copy config
copy: src=vhosts.conf dest=/etc/httpd/conf.d/ owner=app /* 若被其他role调用 注意改 绝对路径 */

vim handlers/main.yml
– name: restart service
service: name=httpd state=restarted

vim vars/main.yml
username: app
groupname: app

cp /etc/httpd/conf/httpd.conf templates/httpd.conf.j2
vim templates/httpd.conf.j2
Listen {{ ansible_processor_vcpus*10 }}
User {{ username }}
Group {{ groupname }}

 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/103709

(0)
倪潇洒倪潇洒
上一篇 2018-07-22
下一篇 2018-07-23

相关推荐