ansible-playbook安装nginx

1.创建一个ansible存放路径https://www.cndba.cn/hbhe0316/article/22182https://www.cndba.cn/hbhe0316/article/22182https://www.cndba.cn/hbhe0316/article/22182

[root@node02 scripts]# mkdir -p /home/monitor/ansible/nginx/{conf,bin}

2.编写nginx.yml文件https://www.cndba.cn/hbhe0316/article/22182

[root@node02:/home/monitor]$ cat /home/monitor/ansible/nginx/bin/nginx.yml 
- hosts: node01 
  remote_user: monitor
  become: yes
  become_method: sudo
  vars:
    hello: Ansible

  tasks:
  - name: Add repo
    yum_repository:
      name: nginx
      description: nginx repo
      baseurl: http://192.168.56.100/epel 
      gpgcheck: no
      enabled: 1
  - name: Install nginx
    yum:
      name: nginx
      state: latest
  - name: Copy nginx configuration file
    copy:
      src: /home/monitor/ansible/nginx/conf/site.conf
      dest: /etc/nginx/conf.d/site.conf
  - name: Start nginx
    service:
      name: nginx
      state: started
  - name: Create wwwroot directory
    file:
      dest: /var/www/html
      state: directory
  - name: Create test page index.html
    shell: echo "hello {{hello}}" > /var/www/html/index.html

3.编写site.conf文件
[root@node02:/home/monitor]$ cat /home/monitor/ansible/nginx/conf/site.conf
server {
listen 80;
server_name 192.168.56.101;
location / {
root /var/www/html;
index index.html;
}
}

4.查看

https://www.cndba.cn/hbhe0316/article/22182
https://www.cndba.cn/hbhe0316/article/22182
[root@node02:/home/monitor]$ tree /home/monitor/ansible/
/home/monitor/ansible/
└── nginx
    ├── bin
    │   └── nginx.yml
    └── conf
        └── site.conf

3 directories, 2 files

5.checkhttps://www.cndba.cn/hbhe0316/article/22182

https://www.cndba.cn/hbhe0316/article/22182
[monitor@node02 bin]$ ansible-playbook -i /home/monitor/hosts /home/monitor/ansible/nginx/bin/nginx.yml --syntax-check

playbook: /home/monitor/ansible/nginx/bin/nginx.yml

6.安装nginx

[monitor@node02 bin]$ ansible-playbook -i /home/monitor/hosts /home/monitor/ansible/nginx/bin/nginx.yml 

PLAY [node01] *************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************
ok: [192.168.56.100]

TASK [Add repo] ***********************************************************************************************************************************************************
changed: [192.168.56.100]

TASK [Install nginx] ******************************************************************************************************************************************************
changed: [192.168.56.100]

TASK [Copy nginx configuration file] **************************************************************************************************************************************
changed: [192.168.56.100]

TASK [Start nginx] ********************************************************************************************************************************************************
changed: [192.168.56.100]

TASK [Create wwwroot directory] *******************************************************************************************************************************************
ok: [192.168.56.100]

TASK [Create test page index.html] ****************************************************************************************************************************************
changed: [192.168.56.100]

PLAY RECAP ****************************************************************************************************************************************************************
192.168.56.100               : ok=7    changed=5    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

7.检查nginx进程https://www.cndba.cn/hbhe0316/article/22182https://www.cndba.cn/hbhe0316/article/22182

[monitor@node02 bin]$ ansible  -i /home/monitor/hosts node01 -m shell -a "ps -ef |grep nginx"
192.168.56.100 | CHANGED | rc=0 >>
root     14311     1  0 13:40 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx    14312 14311  0 13:40 ?        00:00:00 nginx: worker process
nginx    14313 14311  0 13:40 ?        00:00:00 nginx: worker process
nginx    14314 14311  0 13:40 ?        00:00:00 nginx: worker process
nginx    14315 14311  0 13:40 ?        00:00:00 nginx: worker process
monitor  16309 16304  0 13:58 pts/2    00:00:00 /bin/sh -c ps -ef |grep nginx
monitor  16311 16309  0 13:58 pts/2    00:00:00 grep nginx

版权声明:本文为博主原创文章,未经博主允许不得转载。

ansible

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值