Gets error “Cannot get CSRF” when trying to install jenkins-plugin using ANSIBLE

冷暖自知 提交于 2019-12-09 18:58:39

问题


I am using ANSIBLE to install jenkins on CENTOS. The installation works fine but when it comes to the task of installing plugin, i get the following error.

fatal: [jenkins]: FAILED! => {"changed": false, "details": "Request failed: <urlopen error [Errno 111] Connection refused>", "failed": true, "msg": "Cannot get CSRF"}

The code is as follows.

- name: Install jenkins 
rpm_key:
state: present
key: https://pkg.jenkins.io/redhat-stable/jenkins.io.key

- name: Add Repository for jenkins
  yum_repository:
    name: jenkins
    description: Repo needed for automatic installation of Jenkins
    baseurl: http://pkg.jenkins.io/redhat-stable
    gpgcheck: yes
    gpgkey: https://pkg.jenkins.io/redhat-stable/jenkins.io.key

    #Pre requisite: add key and repo
- name: Install jenkins
  yum:
    name: jenkins
    state: present

#Start/Stop jenkins
- name: Start jenkins service
  service:
    name: jenkins
    state: started

#Start jenkins on startup
- name: Start jenkins on boot
  shell: chkconfig jenkins on

- name: Install build-pipeline
  jenkins_plugin:
    name: build-pipeline-plugin
    notify:
      - "restart jenkins-service"

回答1:


You don't seem to wait between starting up jenkins and trying to install the plugin. The jenkins_plugin requires a running and working jenkins installation, so you should do a wait between Start jenkins service and Install build-pipeline:

- name: Wait for Jenkins to start up
  uri:
    url: http://localhost:8080
    status_code: 200
    timeout: 5
  register: jenkins_service_status
  # Keep trying for 5 mins in 5 sec intervals
  retries: 60
  delay: 5
  until: >
     'status' in jenkins_service_status and
     jenkins_service_status['status'] == 200



回答2:


In order to skip the startup wizard, I found this (offcourse googling)

- name: Jenkins Skip startUp for MI
  lineinfile:
    dest=/etc/sysconfig/jenkins
    regexp='^JENKINS_JAVA_OPTIONS='
    line='JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false"'
  register: result_skip_startup_wizard


来源:https://stackoverflow.com/questions/42219781/gets-error-cannot-get-csrf-when-trying-to-install-jenkins-plugin-using-ansible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!