对于Ansiblejenkins_plugin模块返回“HTTP错误403:请求中未包含有效碎屑”感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于ansibleplugins简介、Ansible
对于Ansible jenkins_plugin模块返回“ HTTP错误403:请求中未包含有效碎屑”感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于ansible plugins简介、Ansible+Jenkins+Gitlab搭建及配置、Ansible、jenkins_script 模块和 args 问题、Gitlab_ansible_jenkins 三剑客⑤jenkins Pipeline-job 的使用的有用信息。
本文目录一览:- Ansible jenkins_plugin模块返回“ HTTP错误403:请求中未包含有效碎屑”
- ansible plugins简介
- Ansible+Jenkins+Gitlab搭建及配置
- Ansible、jenkins_script 模块和 args 问题
- Gitlab_ansible_jenkins 三剑客⑤jenkins Pipeline-job 的使用
Ansible jenkins_plugin模块返回“ HTTP错误403:请求中未包含有效碎屑”
我将Ansible(v 2.8)用作Packer模板背后的供应商,以为Jenkins主节点构建AMI。对于以前的版本,剧本已成功通过。但是,从Jenkins
2.176.3版开始,该jenkins_plugin
模块已抛出:
HTTP错误403:请求中未包含有效的屑
我已经检索了面包屑并将其注册在变量中。我尝试将其传递给jenkins_plugin
该http_agent
字段,但这不起作用。我尝试使用attributes
,但这也无济于事。除非我缺少令人难以置信的基本知识,否则我将束手无策。
- name: Get Jenkins Crumb uri: force_basic_auth: yes url_username: **** url_password: **** url: http://localhost:8080/crumbIssuer/api/json return_content: yes register: jenkins_crumb until: jenkins_crumb.content.find(''Please wait while Jenkins is getting ready'') == -1 retries: 10 delay: 5- name: Install plugin jenkins_plugin: name: "{{ item }}" version: latest force_basic_auth: yes url_username: **** url_password: **** http_agent: "Jenkins-Crumb:{{ jenkins_crumb.json.crumb }}" with_items: "{{ jenkins_plugins }}"
我希望安装插件和一个愉快构建的AMI。我得到的是“ HTTP错误403:请求中未包含有效碎屑”,并且Packer构建失败。
答案1
小编典典看起来像2.176 LTS版本中的碎屑发行者所做的更改 强制将初始令牌生成调用的Web会话ID连同碎屑一起包含在使用所述碎屑的后续调用中。
CSRF令牌(小块)现在仅对创建它们的Web会话有效,以限制攻击者获取它们的影响。使用/ crumbIssuer / api
URL获取垃圾的脚本现在将无法执行受CSRF保护的操作,除非脚本在后续请求中保留了Web会话ID。
除了建议您暂时禁用CSRF之外,同一文档还建议您只能禁用新功能,而不能禁用整个CSRF,这应允许您的打包程序/可写程序按照以前的方式完成。
要禁用此改进,可以将系统属性hudson.security.csrf.DefaultCrumbIssuer.EXCLUDE_SESSION_ID设置为true。
编辑:
/etc/default/jenkins
在我自己的剧本(Ansible 2.8.4,Ubuntu 18.04,OpenJDK
11.0.4)中添加以下行可清除CSRF问题。
JAVA_ARGS="$JAVA_ARGS -Dhudson.security.csrf.DefaultCrumbIssuer.EXCLUDE_SESSION_ID=true"
在工具维护人员赶上API更改之前,可能是一个足够好的拐杖。
ansible plugins简介
ansible插件是增强ansible的核心功能的代码片段,ansible使用插件架构来实现丰富,灵活和可扩展的功能集。
1、action插件
2、cache插件
- jsonfile - JSON formatted files.
- memcached - Use memcached DB for cache
- memory - RAM backed, non persistent
- mongodb - Use MongoDB for caching
- pickle - Pickle formatted files.
- redis - Use Redis DB for cache
- yaml - YAML formatted files.
3、callback插件
- actionable - shows only items that need attention
- context_demo - demo callback that adds play/task context
- debug - formated stdout/stderr display
- default - default Ansible screen output
- dense - minimal stdout output
- foreman - Sends events to Foreman
- full_skip - suppresses tasks if all hosts skipped
- hipchat - post task events to hipchat
- jabber - post task events to a jabber server
- json - Ansible screen output as JSON
- junit - write playbook output to a JUnit file.
- log_plays - write playbook output to log file
- logentries - Sends events to Logentries
- logstash - Sends events to Logstash
- mail - Sends failure events via email
- minimal - minimal Ansible screen output
- null - Don’t display stuff to screen
- oneline - oneline Ansible screen output
- osx_say - oneline Ansible screen output
- profile_roles - adds timing information to roles
- profile_tasks - adds time information to tasks
- selective - only print certain tasks
- skippy - Ansible screen output that ignores skipped status
- slack - Sends play events to a Slack channel
- stderr - Splits output, sending failed tasks to stderr
- syslog_json - sends JSON events to syslog
- timer - Adds time to play stats
- tree - Save host events to files
- unixy - condensed Ansible output
- yaml - yaml-ized Ansible screen output
4、inventory插件
- advanced_host_list - Parses a ‘host list’ with ranges
- auto - Loads and executes an inventory plugin specified in a YAML config
- aws_ec2 - ec2 inventory source
- constructed - Uses Jinja2 to construct vars and groups based on existing inventory.
- host_list - Parses a ‘host list’ string
- ini - Uses an Ansible INI file as inventory source.
- k8s - Kubernetes (K8s) inventory source
- openshift - OpenShift inventory source
- openstack - OpenStack inventory source
- script - Executes an inventory script that returns JSON
- virtualbox - virtualbox inventory source
- yaml - Uses a specifically YAML file as inventory source.
5、lookup插件
- aws_account_attribute - Look up AWS account attributes.
- aws_service_ip_ranges - Look up the IP ranges for services provided in AWS such as EC2 and S3.
- aws_ssm - Get the value for a SSM parameter or all parameters under a path.
- cartesian - returns the cartesian product of lists
- chef_databag - fetches data from a Chef Databag
- config - Lookup current Ansilbe configuration values
- conjur_variable - Fetch credentials from CyberArk Conjur.
- consul_kv - Fetch metadata from a Consul key value store.
- credstash - retrieve secrets from Credstash on AWS
- csvfile - read data from a TSV or CSV file
- cyberarkpassword - get secrets from CyberArk AIM
- dict - returns key/value pair items from dictionaries
- dig - query DNS using the dnspython library
- dnstxt - query a domain(s)’s DNS txt fields
- env - read the value of environment variables
- etcd - get info from etcd server
- file - read file contents
- fileglob - list files matching a pattern
- filetree - recursively match all files in a directory tree
- first_found - return first file found from list
- flattened - return single list completely flattened
- hashi_vault - retrieve secrets from HasihCorp’s vault
- hiera - get info from hiera data
- indexed_items - rewrites lists to return ‘indexed items’
- ini - read data from a ini file
- inventory_hostnames - list of inventory hosts matching a host pattern
- items - list of items
- k8s - Query the K8s API
- keyring - grab secrets from the OS keyring
- lastpass - fetch data from lastpass
- lines - read lines from command
- list - simply returns what it is given.
- mongodb - lookup info from MongoDB
- nested - composes a list with nested elements of other lists
- nios - Query Infoblox NIOS objects
- nios_next_ip - Return the next available IP address for a network
- openshift - Query the OpenShift API
- password - retrieve or generate a random password, stored in a file
- passwordstore - manage passwords with passwordstore.org’s pass utility
- pipe - read output from a command
- random_choice - return random element from list
- redis - fetch data from Redis
- redis_kv - fetch data from Redis
- sequence - generate a list based on a number sequence
- shelvefile - read keys from Python shelve file
- subelements - traverse nested key from a list of dictionaries
- template - retrieve contents of file after templating with Jinja2
- together - merges lists into syncronized list
- url - return contents from URL
- vars - Lookup templated value of variables
6、shell插件
- csh - C shell (/bin/csh)
- fish - fish shell (/bin/fish)
- powershell - Windows Powershell
- sh - POSIX shell (/bin/sh)
7、strategy插件
- debug - Executes tasks in interactive debug session.
- free - Executes tasks on each host independently
- linear - Executes tasks in a linear fashion
8、vars插件
- host_group_vars - In charge of loading group_vars and host_vars
9、filters
10、tests
11、插件过滤配置
---
filter_version: ''1.0''
module_blacklist:
# Deprecated
- docker
# We only allow pip, not easy_install
- easy_install
Ansible+Jenkins+Gitlab搭建及配置
Ansible+Jenkins+Gitlab搭建及配置,已经生产环境使用,运行良好。
主机组文件里面好多ip敏感信息就不写了
Ansible、jenkins_script 模块和 args 问题
如何解决Ansible、jenkins_script 模块和 args 问题?
我正在使用这个模块:https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_script_module.html
我想将参数(字典:jenkins_username_password_credentials)传递给我的 Groovy 脚本,该脚本可以更改 Jenkins 上的凭据:
#! / usr / bin / env groovy
import jenkins.model.Jenkins
import com.cloudbees.plugins.credentials.domains.Domain
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl
import com.cloudbees.plugins.credentials.CredentialsScope
import hudson.util.Secret
import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl
instance = Jenkins.instance
domain = Domain.global ()
store = instance.getExtensionList (
"com.cloudbees.plugins.credentials.SystemCredentialsProvider") [0] .getStore ()
{% for credential in jenkins_username_password_credentials%}
usernameAndPassword = new UsernamePasswordCredentialsImpl (
CredentialsScope.GLOBAL,"{{credential [''name'']}}","{{credential [''description'']}}","{{credential [''username'']}}","{{credential [''password'']}}"
)
store.addCredentials (domain,usernameAndPassword)
{% endfor%}
我通过给定的代码做到这一点:
- name: Upload Nexus credentials
jenkins_script:
url: "{{jenkins_url}}"
script: ''{{lookup ("template","templates / jenkins_groovy / credentials / secret_password.groovy")}}''
args:
jenkins_username_password_credentials:
- name: Nexus
description: Credentials for Nexus Server
username: Nexus
password: 25447
user: ''{{jenkins_username}}''
password: ''{{jenkins_password}}''
validate_certs: false
timeout: "120"
但我有一个错误,我的变量 jenkins_username_password_credentials
未定义,直到我将它添加到我角色的默认文件中。
fatal: [jenkins_linux]: Failed! => {"msg": "The task includes an option with an undefined variable. The error was: ''jenkins_username_password_credentials'' is undefined \ n \ nThe error appears to be in'' / home / tbaburin / Ansible / roles / jenkins / tasks / main.yml '': line 3,column 3,but may \ nbe elsewhere in the file depending on the exact Syntax problem. \ n \ nThe offending line appears to be: \ n \ n \ n- name: Upload Nexus credentials \ n ^ here \ n "}
我的问题是:
- 我可以像示例中那样直接在 jenkins_script 模块的“args”字段中声明字典吗? https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_script_module.html
- 如果不能,我该如何更改“args”字段中的字典,以便将包含我需要的数据的修改后的字典加载到脚本中?
我只是不想总是进入默认文件并更改那里的字典数据以加载不同的凭据,我只想将一些 j2 变量传递到 args 中只是为了循环这个,如果我想上传很多凭据。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Gitlab_ansible_jenkins 三剑客⑤jenkins Pipeline-job 的使用
Pipeline-job 的使用
创建 Pipeline 任务
找到 root 用户的 id
编写 pipeline 脚本
#!groovy
pipeline{
agent {node {label ''master''}}
environment {
PATH="/bin/:sbin:usr/bin:usr/sbin:/usr/local/bin"
}
parameters {
choice(
choices: ''dev\nprod'',
description: ''choose deploy environment'',
name: ''deploy_env''
)
string (name: ''version'', defaultValue: ''1.0.0'', description: ''build version'')
}
stages {
stage("checkout test repo") {
steps {
sh ''git config --global http.sslVerify false''
dir ("${env.WORKSPACE}") {
git branch: ''master'', credentialsId: "6bdd72fd-dcc1-4977-9978-4982aae37dc9", url: ''https://root@gitlab.example.com/root/test-repo.git''
}
}
}
stage("Print env variable") {
steps {
dir ("${env.WORKSPACE}") {
sh """
echo "[INFO] print env variable"
echo "current deployment environment is $deploy_env" >> test.properties
echo "the build is $version" >> test.properties
echo "[INFO] Done..."
"""
}
}
}
stage("check test properties") {
steps{
dir ("${env.WORKSPACE}") {
sh """
echo "[INFO] check test properties"
if [ -s test.properties ]
then
cat test.properties
echo "[INFO] done..."
else
echo "test.properties is empty"
fi
"""
echo "[INFO] build finished..."
}
}
}
}
}
编译结果:
Jenkins 与基础应用集成
打开 shell 模块编辑
编写测试脚本
#!/bin/sh
user=`whoami`
if [ $user == ''deploy'' ]
then
echo "hello, my name is $user"
else
echo "sorry, i am not $user"
fi
ip addr
cat /etc/system-release
free -m
df -h
py_cmd=`which python`
$py_cmd --version
带参数的界面
添加参数选项
脚本
#!/bin/sh
echo "current deploy environment is $deploy_env"
echo "the build is $version"
echo "the password is $pass"
if $bool
then
echo "request is appoved"
else
echo "request is rejected"
fi
编译结果
Jenkins 和 git 的集成
我们今天的关于Ansible jenkins_plugin模块返回“ HTTP错误403:请求中未包含有效碎屑”的分享已经告一段落,感谢您的关注,如果您想了解更多关于ansible plugins简介、Ansible+Jenkins+Gitlab搭建及配置、Ansible、jenkins_script 模块和 args 问题、Gitlab_ansible_jenkins 三剑客⑤jenkins Pipeline-job 的使用的相关信息,请在本站查询。
本文标签: