我有一本Ansible剧本,它可以完成以下多项任务-
而且我在剧本中使用过角色,并且角色(repodownload)下载了只希望运行一次的工件,因为为什么我还要再次下载相同的东西。我尝试使用run_once:true,但我想那将不起作用,因为它仅适用于一本Playbook运行,但我的Playbook针对多个主机运行了多次。
---
- name: Deploy my Application to tomcat nodes
hosts: '{{ target_env }}'
serial: 1
roles:
- role: repodownload
tags:
- repodownload
- role: copyrepo
tags:
- copyrepo
- role: stoptomcat
tags:
- stoptomcat
- role: deploy
tags:
- deploy
这里target_env是从命令行传递的,它是远程主机组。任何帮助表示赞赏。
下面是来自repodownload角色的main.yml中的代码-
- connection: local
name: Downloading files from Nexus to local server
get_url: url="{{ nexus_url }}/{{item}}/{{ myvm_release_version }}/{{item}}-{{ release_ver }}.war" dest={{ local_server_location }}
with_items:
- "{{ temps }}"
好的,您可以使用Zeitounator从您的转换器扩展。以下解决方法将在不更改vars文件的情况下起作用。请记住,这是一种解决方法,可能不是最有效的方法。
---
- name: Download my repo to localhost
# Executes only for first host in target_env and has visibility to group vars of target_env
hosts: '{{ target_env }}[0]'
serial: 1
roles:
- role: repodownload
tags:
- repodownload
- name: Deploy my Application to tomcat nodes
# Executes for all hosts in target_env
hosts: '{{ target_env }}'
serial: 1
roles:
- role: copyrepo
tags:
- copyrepo
- role: stoptomcat
tags:
- stoptomcat
- role: deploy
tags:
- deploy