我有以下的playbook打印出三个jenkins服务器上安装的插件列表:
---
- hosts: all
remote_user: user
tasks:
- name: Obtaining a list of Jenkins Plugins
jenkins_script:
script: 'println(Jenkins.instance.pluginManager.plugins)'
url: 'http://server1.usa.com:8080/'
user: 'admin'
password: 'password'
- name: Obtaining a list of Jenkins Plugins
jenkins_script:
script: 'println(Jenkins.instance.pluginManager.plugins)'
url: 'http://server2.usa.com:8080/'
user: 'admin'
password: 'password'
- name: Obtaining a list of Jenkins Plugins
jenkins_script:
script: 'println(Jenkins.instance.pluginManager.plugins)'
url: 'http://server3.usa.com:8080/'
user: 'admin'
password: 'password'
然而,这显然不是最有效的方法。我查看了ansible剧本中的循环和变量 - 但我似乎是在圈子里。以下是我到目前为止的情况:
- name: Obtaining a list of Jenkins Plugins
jenkins_script:
script: 'println(Jenkins.instance.pluginManager.plugins)'
url: {{ item }}
with_items:
- 'http://server1.usa.com:8080/'
- 'http://server2.usa.com:8080/'
- 'http://server3.usa.com:8080/'
user: 'admin'
password: 'password'
以下是错误消息:
fatal: [server]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'item' is undefined\n\nThe error appears to have been in '/home/user/varspb.yml': line 5, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Obtaining a list of Jenkins Plugins\n ^ here\n"}
我确定这是一个简单的错误,但有人知道我哪里出错吗?
答案 0 :(得分:0)
如果您使用HttpStatusCode.NotModified
之类的变量启动值,则需要引用它以插入变量{{ item }}
。此外,您的yaml和任务块中存在各种格式问题。我设法用这个来修复你的任务:
"{{ item }}"