运行剧本时出错

Posted

技术标签:

【中文标题】运行剧本时出错【英文标题】:Error when running playbook 【发布时间】:2019-01-29 00:10:24 【问题描述】:

运行我的第一个剧本时收到错误消息。我创建了一个剧本来在多个主机上应用补丁。

---
- hosts: server01

  vars:
    jboss_home: /apps/middleware/jboss-eap-7.1
    patch_file: patch_url
    patch_dest: /apps/middleware/jboss-eap-7.1
    patch_version: 7.1.3

  tasks:

  - name: Copy patch to target host
    copy:
      src: " patch_file "
      dest: " patch_dest / patch_file "

  - name: Check applied patches
    command: "jboss-cli.sh 'patch history'"
    register: result
    changed_when: "False"

  - name: Apply patch
    command: "jboss-cli.sh 'patch apply  patch_dest / patch_file '"
    when: patch_version not in result.stdout

输出

致命错误 PLAY [server1] ****************************************************** ****************************************** 任务 [收集事实] ****************************************************** ****************************************************** ******* ok: [server1] TASK [复制补丁到目标主机] ****************************************************** *********************************************** 发生异常在任务执行期间。看到完整的 回溯,使用 -vvv。错误是: /apps/middleware/ansible/environments/dev/jboss/patching/patch_url 致命:[server1]:失败! => “更改”:假,“味精”:“找不到 或访问“patch_url”\n已搜索 在:\n\t/apps/middleware/ansible/environments/dev/jboss/patching/files/patch_url\n\t/apps/middleware/ansible/environments/dev/jboss/patching/patch_url\n\t/apps /middleware/ansible/environments/dev/jboss/patching/files/patch_url\n\t/apps/middleware/ansible/environments/dev/jboss/patching/patch_url" 要重试,请使用:--limit @/apps/middleware/ansible/environments/dev/jboss/patching/jboss_patching.retry

【问题讨论】:

嗯,错误的根本原因写在消息Could not find or access 'patch_url'copy模块找不到这个文件中。 谢谢,修复了 url 现在我收到此错误失败:[server1] (item=artifacts-scm.net/artifactory/middleware/jboss/jboss "changed": false, "dest": "/apps/middleware/jboss- eap-7.1”、“gid”:1041、“组”:“mwadm”、“项目”:“http net/artifactory/middleware/jboss/jboss-eap-7.1.3-patch.zip”、“模式”: “0775”、“msg”:“请求失败 t>”、“所有者”:“mwadm”、“seccontext”:“system_u:object_r:etc_runtime_t:s0”、“size”:238、“state”:“director @ 987654322@" 【参考方案1】:

patch_url 文件应该存在于您的patching 角色的files 目录中。 如输出中所述,这是 copy 模块默认查找它的位置,然后是您角色的根目录。

【讨论】:

谢谢,现在修复错误失败:[server1] (item=artifacts-scm.net/artifactory/middleware/jboss/jboss "changed": false, "dest": "/apps/middleware/jboss-eap-7.1", “gid”:1041,“组”:“mwadm”,“项目”:“http net/artifactory/middleware/jboss/jboss-eap-7.1.3-patch.zip”,“模式”:“0775”,“ msg": "请求失败 t>", "owner": "mwadm", "seccontext": "system_u:object_r:etc_runtime_t:s0", "size": 238, "state": "director artifacts-scm.net/artifactory/middleware/jboss/…" “mode”:“0775”,“msg”:“请求失败:”,“owner”:“mwadm”,“secontext”:“system_u:object_r:etc_runtime_t :s0", "size": 238, "state": "directory", "uid": 1040, "url": "我的 url - "artifacts-scm.net/artifactory/middleware/jboss/…"

以上是关于运行剧本时出错的主要内容,如果未能解决你的问题,请参考以下文章

如何控制Ansible Playbook的执行顺序运行选定的剧本资源

关于如何控制Ansible Playbook的执行顺序运行选定的剧本资源的一些笔记

Ansible的脚本—playbook剧本

ansible-playbook剧本

如何在剧本中设置Ansible标签?

将剧本运行中的变量保存到 ansible 主机本地文件