包括ansible剧本中的子角色?
我有一个需要其他角色的ansible角色,但没有从我的剧本中正确加载。我的角色在这里,它依赖于另外两个geerlingguy角色,如下所示包括ansible剧本中的子角色?,ansible,Ansible,我有一个需要其他角色的ansible角色,但没有从我的剧本中正确加载。我的角色在这里,它依赖于另外两个geerlingguy角色,如下所示 meta/main.yml galaxy_info: author: Jd Daniel description: Jenkins installer company: GE Health min_ansible_version: 2.2 role_name: jenkins license: GPLv3 platforms
meta/main.yml
galaxy_info:
author: Jd Daniel
description: Jenkins installer
company: GE Health
min_ansible_version: 2.2
role_name: jenkins
license: GPLv3
platforms:
- name: EL
versions:
- 7
galaxy_tags:
- jenkins
- deployment
- continuous-deployment
- cd
dependencies:
- { role: geerlingguy.repo-epel }
- { role: geerlingguy.jenkins, jenkins_plugins: [] }
---
- name: Install required roles
include_role:
name: "{{ roles }}"
vars:
roles:
- geerlingguy.epel-repo
- geerlingguy.jenkins
.... other tasks ....
#
# Ansible to provision Jenkins on remote host
#
- name: Install Jenkins and its plugins
hosts: all
become: yes
become_method: sudo
gather_facts: yes
vars:
jenkins_hostname: localhost
jenkins_http_port: 8080
roles:
- ehime.jenkins
pre_tasks:
- name: CA-Certificates update command line execution
command: /bin/update-ca-trust
tasks:
- name: Set up pipeline
jenkins_job:
config: "{{ lookup('file', 'files/job.xml') }}"
name: test-auto
user: "{{ jenkins_admin_username }}"
password: "{{ jenkins_admin_password }}"
此角色中的我的角色ansible.cfg
也指向roles/
目录
[defaults]
# without this, the connection to a new instance is interactive
host_key_checking = False
roles_path = roles/
并将角色下载到roles/
文件夹中
┌─[10:25:24]─[ehime@GC02WW38KHTD6E]─[~/Repositories/Infra/Ansible/ansible-role-jenkins]
└──> tree -L 2
.
├── [ehime 34K] LICENSE
├── [ehime 1.3K] README.md
├── [ehime 128] ansible.cfg
├── [ehime 96] defaults
│ └── [ehime 32] main.yml
├── [ehime 96] files
│ └── [ehime 633] job.xml
├── [ehime 96] handlers
│ └── [ehime 33] main.yml
├── [ehime 96] meta
│ └── [ehime 417] main.yml
├── [ehime 160] roles
│ ├── [ehime 384] geerlingguy.java
│ ├── [ehime 416] geerlingguy.jenkins
│ └── [ehime 320] geerlingguy.repo-epel
├── [ehime 96] tasks
│ └── [ehime 737] main.yml
├── [ehime 352] tests
│ ├── [ehime 669] README.md
│ ├── [ehime 276] Vagrantfile
│ ├── [ehime 121] ansible.cfg
│ ├── [ehime 203] inventory
│ ├── [ehime 221] requirements.yml
│ ├── [ehime 96] roles
│ ├── [ehime 10] test_7_default.retry
│ └── [ehime 182] test_7_default.yml
└── [ehime 96] vars
└── [ehime 91] main.yml
我的任务应该是把它们拉进来?对吧?
tasks/main.yml
galaxy_info:
author: Jd Daniel
description: Jenkins installer
company: GE Health
min_ansible_version: 2.2
role_name: jenkins
license: GPLv3
platforms:
- name: EL
versions:
- 7
galaxy_tags:
- jenkins
- deployment
- continuous-deployment
- cd
dependencies:
- { role: geerlingguy.repo-epel }
- { role: geerlingguy.jenkins, jenkins_plugins: [] }
---
- name: Install required roles
include_role:
name: "{{ roles }}"
vars:
roles:
- geerlingguy.epel-repo
- geerlingguy.jenkins
.... other tasks ....
#
# Ansible to provision Jenkins on remote host
#
- name: Install Jenkins and its plugins
hosts: all
become: yes
become_method: sudo
gather_facts: yes
vars:
jenkins_hostname: localhost
jenkins_http_port: 8080
roles:
- ehime.jenkins
pre_tasks:
- name: CA-Certificates update command line execution
command: /bin/update-ca-trust
tasks:
- name: Set up pipeline
jenkins_job:
config: "{{ lookup('file', 'files/job.xml') }}"
name: test-auto
user: "{{ jenkins_admin_username }}"
password: "{{ jenkins_admin_password }}"
当运行我的剧本时
jenkins.yml
galaxy_info:
author: Jd Daniel
description: Jenkins installer
company: GE Health
min_ansible_version: 2.2
role_name: jenkins
license: GPLv3
platforms:
- name: EL
versions:
- 7
galaxy_tags:
- jenkins
- deployment
- continuous-deployment
- cd
dependencies:
- { role: geerlingguy.repo-epel }
- { role: geerlingguy.jenkins, jenkins_plugins: [] }
---
- name: Install required roles
include_role:
name: "{{ roles }}"
vars:
roles:
- geerlingguy.epel-repo
- geerlingguy.jenkins
.... other tasks ....
#
# Ansible to provision Jenkins on remote host
#
- name: Install Jenkins and its plugins
hosts: all
become: yes
become_method: sudo
gather_facts: yes
vars:
jenkins_hostname: localhost
jenkins_http_port: 8080
roles:
- ehime.jenkins
pre_tasks:
- name: CA-Certificates update command line execution
command: /bin/update-ca-trust
tasks:
- name: Set up pipeline
jenkins_job:
config: "{{ lookup('file', 'files/job.xml') }}"
name: test-auto
user: "{{ jenkins_admin_username }}"
password: "{{ jenkins_admin_password }}"
但在尝试运行以下剧本时
#
# Ansible to provision Jenkins on remote host
#
- name: Install Jenkins and its plugins
hosts: all
become: yes
become_method: sudo
gather_facts: yes
vars:
jenkins_hostname: localhost
jenkins_http_port: 8080
roles:
- ehime.jenkins
pre_tasks:
- name: CA-Certificates update command line execution
command: /bin/update-ca-trust
tasks:
- name: Set up pipeline
jenkins_job:
config: "{{ lookup('file', 'files/job.xml') }}"
name: test-auto
user: "{{ jenkins_admin_username }}"
password: "{{ jenkins_admin_password }}"
用我的剧本配置
ansible.cfg
[defaults]
# without this, the connection to a new instance is interactive
host_key_checking = False
roles_path = roles/
remote_user = ec2-user
private_key_file = ../_keys/test-jenkins
我得到以下错误
错误
TASK [include_role : {{ roles }}] ************************************************************************************************************************************************************************************************************
ERROR! Invalid role definition: [u'geerlingguy.epel-repo', u'geerlingguy.jenkins']
显然,在
roles/ehime.jenkins/roles
中没有看到角色,但我不确定如何让它们工作。对于galaxy安装,它似乎也忽略了我的meta/main.yml
?这些应该在requirements.yml
中吗?像个白痴一样,我的依赖项太多了
galaxy_info:
author: Jd Daniel
description: Jenkins installer
company: GE Health
min_ansible_version: 2.2
role_name: jenkins
license: GPLv3
platforms:
- name: EL
versions:
- 7
galaxy_tags:
- jenkins
- deployment
- continuous-deployment
- cd
# Issue is here....
dependencies:
- { role: geerlingguy.repo-epel }
- { role: geerlingguy.jenkins, jenkins_plugins: [] }
应该是
galaxy_info:
author: Jd Daniel
description: Jenkins installer
company: GE Health
min_ansible_version: 2.2
role_name: jenkins
license: GPLv3
platforms:
- name: EL
versions:
- 7
galaxy_tags:
- jenkins
- deployment
- continuous-deployment
- cd
# Issue is here....
dependencies:
- { role: geerlingguy.repo-epel }
- { role: geerlingguy.jenkins, jenkins_plugins: [] }