www.91084.com

GVKun编程网logo

Ansible jenkins_plugin模块返回“ HTTP错误403:请求中未包含有效碎屑”

17

对于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 jenkins_plugin模块返回“ HTTP错误403:请求中未包含有效碎屑”

我将Ansible(v 2.8)用作Packer模板背后的供应商,以为Jenkins主节点构建AMI。对于以前的版本,剧本已成功通过。但是,从Jenkins
2.176.3版开始,该jenkins_plugin模块已抛出:

HTTP错误403:请求中未包含有效的屑

我已经检索了面包屑并将其注册在变量中。我尝试将其传递给jenkins_pluginhttp_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 plugins简介

ansible插件是增强ansible的核心功能的代码片段,ansible使用插件架构来实现丰富,灵活和可扩展的功能集。

Ansible提供了许多方便的插件,您可以轻松编写自己的插件。
下边简单介绍Ansible包含的各种插件(插件具体用法请参考官方文档或者ansible-doc):

1、action插件

Action插件与模块一起执行PlayBook任务所需的操作。它们通常在后台自动执行,在模块执行之前进行必要的工作。
“normal” action插件 用于尚未拥有action插件的模块。
您可以启用一个自定义操作插件,方法是将其放置到与role中的play相邻的action_plugins目录中,
当使用关联模块时,Action插件默认执行;不需要采取任何行动

2、cache插件

缓存插件实现的后端缓存机制,可以使ansible存储获得的facts和inventory元数据,不必再从源头检索这些数据,而降低性能。
默认的缓存插件是memory plugin,它只缓存ansible目前执行的数据,其他持久存储的插件也可以缓存数据
  • 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插件

回调插件可以在响应事件时向Ansible添加新行为。
默认情况下,回调插件控制运行命令行程序时看到的大部分输出,
但也可用于添加其他输出,与其他工具集成并将事件整理到存储后端。
  • 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插件

清单插件允许用户指向数据源,以便通过-i  /path/to/file和/ 或-i ''host1,host2 命令行参数
或其他配置来源编译Ansible用于定位任务的主机清单。
个人觉得ini最好用
  • 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插件

查找插件允许Ansible从外部来源访问数据。这可以包括:联系外部数据存储和服务,读取文件系统。
查找插件返回的数据可以使用Ansible中的标准模板系统提供,通常用于从这些系统中加载包含信息的变量或模板。
lookups是Jinja2模板语言的Ansible特定扩展。
  • 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插件

Shell插件可以确保Ansible运行的基本命令格式正确,可与目标机器一起使用,并允许用户配置某些与Ansible执行任务相关的行为
  • csh - C shell (/bin/csh)
  • fish - fish shell (/bin/fish)
  • powershell - Windows Powershell
  • sh - POSIX shell (/bin/sh)

7、strategy插件

策略插件通过处理play和hosts调度 来控制play执行的流程。
  • debug - Executes tasks in interactive debug session.
  • free - Executes tasks on each host independently
  • linear - Executes tasks in a linear fashion

8、vars插件

Vars插件将额外的变量注入到Ansible中运行,这些运行不是来自库存源,剧本或命令行。
Playbook使用vars插件构建像''host_vars''和''group_vars''的工作目录。
Vars插件在Ansible 2.0中部分实现,并被重写为从Ansible 2.4开始全面实施。
Ansible附带的host_group_vars插件可以从主机变量和组变量中读取变量。
  • host_group_vars - In charge of loading group_vars and host_vars

9、filters

Ansible中的过滤器来自Jinja2,用于转换模板表达式中的数据。
Jinja2附带很多过滤器。请参阅官方Jinja2模板文档中的内置过滤器。
考虑到 模板产生 在Ansible控制器上,而不是在任务的目标主机上,所以过滤器也在控制器上执行,因为它们处理本地数据。
除了jinja2,Ansible附带自己的产品,并允许用户添加他们自己的自定义过滤器。
 

10、tests

Jinja中的tests是评估模板表达式,并返回True或False的一种方式,Jinja附带许多这些。在官方Jinja模板文档中查看内置测试。
tests和filters之间的主要区别在于Jinja tests用于比较,而filters用于数据处理,并且在jinja中有不同的应用程序,如map()和select()来选择列表中的项目。
像所有模板一样,tests总是在Ansible控制器上执行,而不是在任务的目标上执行,因为他们测试本地数据。
除了jinjia2 tests,Ansible提供更多功能,用户可以自己轻松创建。
 

11、插件过滤配置

Ansible 2.5为站点管理员添加了模块黑名单,用于禁用Ansible的某些模块。
这是通过yaml配置文件配置的(默认为/etc/ansible/plugin_filters.yml)。该文件的格式是:
---
filter_version: ''1.0''
module_blacklist:
# Deprecated
- docker
# We only allow pip, not easy_install
- easy_install

 

Ansible+Jenkins+Gitlab搭建及配置

Ansible+Jenkins+Gitlab搭建及配置

Ansible+Jenkins+Gitlab搭建及配置,已经生产环境使用,运行良好。

主机组文件里面好多ip敏感信息就不写了

 

 

 

 

 

 

Ansible、jenkins_script 模块和 args 问题

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 的使用

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 的使用的相关信息,请在本站查询。

本文标签: