ansible-galaxy的应用

ansible-galaxy的应用

ansible-galaxy 部署nginx

1.相关命令

1. 查看本机已安装的角色
[root@server ansible]# ansible-galaxy list
- ansible-role-nginx, (unknown version)

2. 联网安装ansible的角色
[root@server ansible]# ansible-galaxy install geerlingguy.nginx

3. 卸载角色
[root@server ansible]# ansible-galaxy remove ansible-role-nginx
- successfully removed ansible-role-nginx

2. 访问galaxy.ansible.com 查找自己想要的角色

在这里插入图片描述
点击搜索 进行roles的检索
在这里插入图片描述
找到自己需要的角色 点击查看详情 这里建议根据评分和下载量进行选择 选择接近5分的优质角色(通过下载量识别大佬和菜鸡)
在这里插入图片描述

点击头像,进入主页,到主页的个人作品搜索框内,输入nginx,进行查找,查找后点击nginx,进入作品详细页面。
在这里插入图片描述
在这里插入图片描述

3. 角色获取

鉴于国内网络连接galaxy.ansible.com比较费劲 建议访问GitHub获取角色文件 点击【github repo】即可跳转到 GitHub

复制项目地址 进行角色文件的克隆

在这里插入图片描述

root@server ansible]# yum -y install git
[root@server ansible]# git clone https://github.com/geerlingguy/ansible-role-nginx.git
正克隆到 'ansible-role-nginx'...
remote: Enumerating objects: 976, done.
remote: Counting objects: 100% (35/35), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 976 (delta 12), reused 20 (delta 8), pack-reused 941
接收对象中: 100% (976/976), 162.77 KiB | 900.00 KiB/s, 完成.
处理 delta 中: 100% (460/460), 完成.

4.角色的使用

[root@server ansible]# cp -a ansible-role-nginx/ /etc/ansible/roles/
[root@server ansible]# ls
ansible.cfg  ansible-role-nginx  hosts  inventory  playbook  roles  run.yml
[root@server ansible]# rm -rf ansible-role-nginx/
[root@server ansible]# ls
ansible.cfg  hosts  inventory  playbook  roles  run.yml

[root@server ansible]# vim nginx.yml  //编写playbook
---
- hosts: all
  remote_user: root
  roles:
    - role: ansible-role-nginx
   
[root@server ansible]# ansible-playbook --syntax-check nginx.yml  //测试

playbook: nginx.yml

[root@server ansible]# ansible-playbook nginx.yml  //执行

PLAY [httpd] *********************************************************************

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

TASK [ansible-role-nginx : Include OS-specific variables.] ***********************
ok: [192.168.58.20]

TASK [ansible-role-nginx : Define nginx_user.] ***********************************
ok: [192.168.58.20]

TASK [ansible-role-nginx : include_tasks] ****************************************
included: /etc/ansible/roles/ansible-role-nginx/tasks/setup-RedHat.yml for 192.168.58.20

TASK [ansible-role-nginx : Enable nginx repo.] ***********************************
changed: [192.168.58.20]

TASK [ansible-role-nginx : Ensure nginx is installed.] ***************************
changed: [192.168.58.20]

TASK [ansible-role-nginx : include_tasks] ****************************************
skipping: [192.168.58.20]

TASK [ansible-role-nginx : include_tasks] ****************************************
skipping: [192.168.58.20]

TASK [ansible-role-nginx : include_tasks] ****************************************
skipping: [192.168.58.20]

TASK [ansible-role-nginx : include_tasks] ****************************************
skipping: [192.168.58.20]

TASK [ansible-role-nginx : include_tasks] ****************************************
skipping: [192.168.58.20]

TASK [ansible-role-nginx : Remove default nginx vhost config file (if configured).] ***
skipping: [192.168.58.20]

TASK [ansible-role-nginx : Ensure nginx_vhost_path exists.] **********************
ok: [192.168.58.20]

TASK [ansible-role-nginx : Add managed vhost config files.] **********************

TASK [ansible-role-nginx : Remove managed vhost config files.] *******************

TASK [ansible-role-nginx : Remove legacy vhosts.conf file.] **********************
ok: [192.168.58.20]

TASK [ansible-role-nginx : Copy nginx configuration in place.] *******************
changed: [192.168.58.20]

TASK [ansible-role-nginx : Ensure nginx service is running as configured.] *******
changed: [192.168.58.20]

RUNNING HANDLER [ansible-role-nginx : reload nginx] ******************************
changed: [192.168.58.20]

PLAY RECAP ***********************************************************************
192.168.58.20              : ok=11   changed=5    unreachable=0    failed=0    skipped=8    rescued=0    ignored=0   

5.验证

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值