当前位置: 代码迷 >> 综合 >> ansible基出用法4_ansible-galaxy
  详细解决方案

ansible基出用法4_ansible-galaxy

热度:26   发布时间:2024-02-19 10:46:50.0

 ansible-galaxy 可以从网站上拉取别人写好的playbook ,

连接https://galaxy.ansible.com 下载相应的roles
ansible-galaxy list
安装galaxy
ansible-galaxy install geerlingguy.nginxansible-galaxy install geerlingguy.nginx
- downloading role 'nginx', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-nginx/archive/2.8.0.tar.gz
- extracting geerlingguy.nginx to /etc/ansible/roles/geerlingguy.nginx
- geerlingguy.nginx was installed successfully
[root@ansible ~]# cd /etc/ansible/roles/

 

也可以手动创建一个playbook,ansible-galaxy提供一个创建playbook模板的用法,就是初始化一个roles

[root@ansible ansible]# ansible-galaxy init roles/redis -f
- roles/redis was created successfully

#查看目下下面已经有个这个目录

[root@ansible ansible]# cd roles/
app/               Coding/            geerlingguy.nginx/ httpd/             hycloud/           memcache/          mysql/             nginx/             redis/

#模板的文件和格式也已经创建完成,就可以按照这个模板进行创建

[root@ansible ansible]# tree roles/redis/
roles/redis/
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars└── main.yml8 directories, 8 files
[root@ansible ansible]#