0. ansible-galaxy相关命令
1. 查看本机已安装的角色
[root@localhost ansible]# ansible-galaxy list
- ansible-role-nginx, (unknown version)
2. 联网安装ansible的角色
[root@localhost ansible]# ansible-galaxy install geerlingguy.nginx
3. 卸载角色
[root@localhost ansible]# ansible-galaxy remove ansible-role-nginx
- successfully removed ansible-role-nginx
1. 访问galaxy.ansible.com 查找自己想要的角色
点击搜索 进行roles的检索
找到自己需要的角色 点击查看详情 这里建议根据评分和下载量进行选择 选择接近5分的优质角色
2. 角色获取
鉴于国内网络连接galaxy.ansible.com比较费劲 建议访问GitHub获取角色文件 点击【github repo】即可跳转到 GitHub
复制项目地址 进行角色文件的克隆
[root@localhost ~]# yum -y install git
[root@localhost ~]# git clone https://github.com/geerlingguy/ansible-role-nginx.git
Cloning into 'ansible-role-nginx'...
remote: Enumerating objects: 855, done.
remote: Total 855 (delta 0), reused 0 (delta 0), pack-reused 855
Receiving objects: 100% (855/855), 138.54 KiB | 20.00 KiB/s, done.
Resolving deltas: 100% (407/407), done.
3. 角色的使用
[root@localhost ~]# cp -a ansible-role-nginx/ /etc/ansible/roles/
[root@localhost ~]# cd /etc/ansible/
[root@localhost ansible]# ls
ansible.cfg hosts roles
[root@localhost ansible]# vim nginx.yml
- hosts: all
remote_user: root
roles:
- role: ansible-role-nginx
检测语法并使用角色
[root@localhost ansible]# ansible-playbook nginx.yml --syntax-check
playbook: nginx.yml
[root@localhost ansible]# ansible-playbook nginx.yml
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.20.106]
TASK [ansible-role-nginx : Include OS-specific variables.] *********************
ok: [192.168.20.106]
TASK [ansible-role-nginx : Define nginx_user.] *********************************
ok: [192.168.20.106]
TASK [ansible-role-nginx : include_tasks] **************************************
included: /etc/ansible/roles/ansible-role-nginx/tasks/setup-RedHat.yml for 192.168.20.106
TASK [ansible-role-nginx : Enable nginx repo.] *********************************
ok: [192.168.20.106]
TASK [ansible-role-nginx : Ensure nginx is installed.] *************************
changed: [192.168.20.106]
TASK [ansible-role-nginx : include_tasks] **************************************
skipping: [192.168.20.106]
TASK [ansible-role-nginx : include_tasks] **************************************
skipping: [192.168.20.106]
TASK [ansible-role-nginx : include_tasks] **************************************
skipping: [192.168.20.106]
TASK [ansible-role-nginx : include_tasks] **************************************
skipping: [192.168.20.106]
TASK [ansible-role-nginx : include_tasks] **************************************
skipping: [192.168.20.106]
TASK [ansible-role-nginx : Remove default nginx vhost config file (if configured).] ***
skipping: [192.168.20.106]
TASK [ansible-role-nginx : Ensure nginx_vhost_path exists.] ********************
ok: [192.168.20.106]
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.20.106]
TASK [ansible-role-nginx : Copy nginx configuration in place.] *****************
changed: [192.168.20.106]
TASK [ansible-role-nginx : Ensure nginx service is running as configured.] *****
changed: [192.168.20.106]
RUNNING HANDLER [ansible-role-nginx : reload nginx] ****************************
changed: [192.168.20.106]
PLAY RECAP *********************************************************************
192.168.20.106 : ok=11 changed=4 unreachable=0 failed=0
4. 验证
访问被控端ip 看是否可以访问到nginx的页面
firefox http://192.168.20.106