Atul Agrawal
Atul Agrawal

Reputation: 1520

Unable to install jenkins from ansible

I want to automate installation of jenkins and for that i am using ansible. I am trying to install jenkins with its repo and gpg key. This is my playbook

---
- hosts: "{{ HOST }}"
  become: true
  become_user: root
  gather_facts: true
  become_method: sudo

  vars:
    temp_folder: /tmp

  tasks:
    - name: Include variables
      include_vars:
        dir: '../vars'
        extensions: ['yml']

    - name: Install java  
      yum:    
        name: java    
        state: present    
        update_cache: yes
      become: true
      become_user: root

    - name: Add Jenkins Repository | Add Sources List
      yum_repository:
        name: jenkins
        description: jenkins
        baseurl: "{{ jenkins_repo }}"
        gpgkey: "{{ jenkins_key }}"
        gpgcheck: yes
      become: true
      become_user: root

    - name: Install jenkins 
      yum:
        name: jenkins
        state: present    
        update_cache: yes
      become_user : root
      become: true

    - name: Start Jenkins Service | Enable on Boot
      service:
        name: jenkins
        state: started
        enabled: yes
      become: true
      become_user: root

the values in var file contains following keys:- ---

jenkins_key: https://pkg.jenkins.io/redhat/jenkins.io.key
jenkins_repo: https://pkg.jenkins.io/redhat/jenkins.repo

Now when i am executing playbook it throwing me following error.

fatal: [atul-ec2]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "conf_file": null, 
            "disable_gpg_check": false, 
            "disablerepo": null, 
            "enablerepo": null, 
            "exclude": null, 
            "install_repoquery": true, 
            "installroot": "/", 
            "list": null, 
            "name": [
                "jenkins"
            ], 
            "skip_broken": false, 
            "state": "present", 
            "update_cache": true, 
            "validate_certs": true
        }
    }, 
    "msg": "Failure talking to yum: failure: repodata/repomd.xml from jenkins: [Errno 256] No more mirrors to try.\nhttps://pkg.jenkins.io/redhat/jenkins.repo/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found"
}

But when i am trying to add jenkins repo manually it is not throwing me any error.

Upvotes: 1

Views: 1113

Answers (2)

bazeusz
bazeusz

Reputation: 614

I know it's quite an old thread.

But as an accepted answer doesn't really explain why the code in question did not work as expected, please find a few words below

  • yum_repository ansible module creates a .repo file/definition from provided properties
  • the uri in the jenkins_repo variable provided in the question points to the .repo file/definition itself thus using the yum_repository is not appropriate in this case and if one wants to use this definition using the get_url module is the way to go

Using the latter may be a better choice here especially as that's provided by the software maintainer.

Upvotes: 0

Matthew Schuchard
Matthew Schuchard

Reputation: 28739

The baseurl parameter is supposed to contain a value pointing to the URL containing the packages and the repodata. The value you supplied is for the file containing the yum repo information. You need to pull the baseurl from that file and use it for the value. In your example of redhat, your value should be:

jenkins_repo: https://pkg.jenkins.io/redhat/

The repo will be properly configured using the repodata/repomod.xml contained in that directory when the jenkins_repo variable is used with the baseurl parameter as you are using it in the yum_repository module in your task.

Upvotes: 1

Related Questions