1
votes

I have a ansible role that requires other roles, but is not loading correctly from my playbook. My role is here, Jenkins Role, it has dependencies on two other geerlingguy roles, which are listed here

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

My roles ansible.cfg in this role also points to the roles/ directory

[defaults]
# without this, the connection to a new instance is interactive
host_key_checking = False
roles_path        = roles/

and the roles are downloaded into the roles/ folder

┌─[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

My tasks should be pulling these in then? right?

tasks/main.yml

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

.... other tasks ....

When running my playbook though...

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 }}"

When trying to run the following playbook though

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

With my playbooks config...

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

I get the following error....

error

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

It's evidently NOT seeing the roles in roles/ehime.jenkins/roles but I'm not sure how to get those working. It also seem like it ignores my meta/main.yml for a galaxy install? Should these be in the requirements.yml?

1

1 Answers

2
votes

Like an idiot, I had my dependencies tabbed in too far...

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

should have been

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