Muh*_*Haq 6 csrf jenkins jenkins-plugins ansible
我正在使用 ANSIBLE 在 CENTOS 上安装 jenkins。安装工作正常,但是当涉及到安装插件的任务时,我收到以下错误。
fatal: [jenkins]: FAILED! => {"changed": false, "details": "Request failed: <urlopen error [Errno 111] Connection refused>", "failed": true, "msg": "Cannot get CSRF"}
Run Code Online (Sandbox Code Playgroud)
代码如下。
- 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"
Run Code Online (Sandbox Code Playgroud)
您似乎没有在启动詹金斯和尝试安装插件之间等待。这需要一个正在运行和工作的 jenkins 安装,所以你应该在和jenkins_plugin之间等待:Start jenkins serviceInstall 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
Run Code Online (Sandbox Code Playgroud)