在辅助剧本中包括子角色吗?

时间:2018-10-25 17:39:43

标签: ansible

我有一个忙碌的角色,需要其他角色,但不能从我的剧本正确加载。我的角色是Jenkins Role,它与其他两个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:
    - name: EL
      versions:
        - 7

  galaxy_tags:
    - jenkins
    - deployment
    - continuous-deployment
    - cd

  dependencies:
    - { role: geerlingguy.repo-epel }
    - { role: geerlingguy.jenkins, jenkins_plugins: [] }

我在此角色中的角色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

---
- name: Install required roles
  include_role:
    name: "{{ roles }}"
  vars:
    roles:
      - geerlingguy.epel-repo
      - geerlingguy.jenkins

.... other tasks ....

虽然运行我的剧本时...

jenkins.yml

#
# 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

我收到以下错误...。

error

TASK [include_role : {{ roles }}] ************************************************************************************************************************************************************************************************************
ERROR! Invalid role definition: [u'geerlingguy.epel-repo', u'geerlingguy.jenkins']

显然没有看到roles/ehime.jenkins/roles中的角色,但我不确定如何使它们起作用。好像也忽略了我的meta/main.yml进行银河安装?这些应该放在requirements.yml中吗?

1 个答案:

答案 0 :(得分:0)

像个白痴一样,我的依附关系太远了……

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: [] }