ansible实战

[root@slave1 ~]# tree ansible/
ansible/
├── group_vars
│   └── all
├── hosts
├── host_vars
│   └── 192.168.56.12
├── roles
│   └── nginx
│   ├── files
│   │   └── index.html
│   ├── handlers
│   │   └── main.yaml
│   ├── tasks
│   │   └── main.yaml
│   └── templates
│   └── nginx.conf.j2
├── site.retry
└── site.yaml

8 directories, 9 files
[root@slave1 ~]#

#####################################################################
[root@slave1 ~]# cat ansible/group_vars/all
version: 1.12.2
user: root
[root@slave1 ~]#

#####################################################################
[root@slave1 ~]# cat ansible/host_vars/192.168.56.12
worker_connections: 12400
[root@slave1 ~]#
#####################################################################
[root@slave1 ~]# cat ansible/roles/nginx/files/index.html
index
[root@slave1 ~]#
#####################################################################
[root@slave1 ~]# cat ansible/roles/nginx/handlers/main.yaml

  • name: restart nginx
    service: name=nginx state=restarted
    [root@slave1 ~]#
    #####################################################################
    [root@slave1 ~]# cat ansible/roles/nginx/tasks/main.yaml
  • name: install nginx
    yum: name=nginx-{{ version }} state=present
  • name: copy templates
    template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf owner=root mode=644
    notify: restart nginx
  • name: copy index.html
    copy: src=index.html dest=/usr/share/nginx/html/index.html force=yes owner=root mode=644
  • name: start nginx
    service: name=nginx state=started
    [root@slave1 ~]#
    #####################################################################
    cat ansible/roles/nginx/templates/nginx.conf.j2

    user {{ user }};
    worker_processes {{ ansible_processor_cores }};
    worker_connections {{ worker_connections }};
    #####################################################################
    [root@slave1 ansible]# cat site.yaml

  • name: Install nginx
    hosts: one
    become: True
    roles:
    • nginx
      [root@slave1 ansible]#
      #####################################################################
      ansible-playbook -i hosts site.yaml

转载于:https://blog.51cto.com/wsxxsl/2048775

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值