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/103710

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

相关推荐

  • shell脚本之判断httpd是否有异常

    案例 以web为例 大全讲解:如http为例 #/etc/init.d/httpd start      开启httpd #lsof –i :80 [root@centos6 ~/bin]$curl -I -s -o /dev/null -w “%{http_code}\n” http://172.16.0.1 析:-I 是响应头,响…

    Linux笔记 2018-05-20
  • 变量的理解

    有点绕多动动手就好了

    Linux笔记 2018-04-15
  • 第一周 笔记

    ../返回上一层 相对路径绝对路径    ../../   以根开始绝对路径 不以根开始是相对路径 alias 简化特别长得命令和参数(别名)  unalias去掉别名使用 .bashrc    -a全取消 ls .bashrc 别名目录文件 basename   查看主机名  (取最后的文件名) bc 计算器   obase=几进制  进制转换 clock…

    Linux笔记 2018-04-01
  • linux通配符和正则表达式

    通配符、正则表达式

    2018-04-17
  • linux基础之自动登陆和自动开启网卡设置

    Centos7.4设置自动登陆以及设置网卡开机自动启用功能 1、进入命令行模式,输入 nano /etc/gdm/custom.conf ,在[daemon]下添加2条命令,分别是 AutomaticLoginEnable=true AutomaticLogin=root 2、然后按住Ctrl+X退出并保存,接着选择Y,再按回车键即可保存更改,到这里设置自动…

    2018-03-29
  • ansible的简介和用法

    Ansible  (底层是基于ssh连接的,每次操作其他主机需要输入密码 ,所以首先要实现基于key的公钥验证) 使用ansible: ansible "192.168.60.3" -m shell -a 'ls /root' -k (单个用户在实现基于key的验证前) 安装ansible: yum包的安装:…

    2018-05-28