我有一个行动手册,其中包含要在远程主机上执行的一些角色/任务。在一个场景中,我希望一些任务在本地执行,比如将工件从svn/nexus下载到本地服务器。
下面是我的主要攻略,我从命令行传递target_env并使用group_vars目录动态加载变量
---
- name: Starting Deployment of Application to tomcat nodes
hosts: '{{ target_env }}'
become: yes
become_user: tomcat
become_method: sudo
gather_facts: yes
roles:
- role: repodownload
tags:
- repodownload
- role: stoptomcat
tags:
- stoptomcat第一个角色repodownload实际上是将工件从svn/nexus下载到本地服务器/控制器。下面是这个角色的main.yml -
- name: Downloading MyVM Artifacts on the local server
delegate_to: localhost
get_url: url="http://nexus.com/myrelease.war" dest=/tmp/releasename/
- name: Checkout latest application configuration templates from SVN repo to local server
delegate_to: localhost
subversion:
repo: svn://12.57.98.90/release-management/config
dest: ../templates
in_place: yes但它不起作用。会不会是因为在我的主yml文件中,我成为了想要在远程主机上执行命令的用户。
如果有人能帮上忙,请告诉我。我会很感激的。
错误-
"changed": false,
"module_stderr": "sudo: a password is required\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}发布于 2020-05-13 21:11:31
在给定场景的情况下,您可以通过多种方式来实现。其中之一可能是在仅在本地主机上运行的主剧本中添加另一个用于repodownload角色的play。然后从角色tasks中删除delegate_to: localhost,并相应地移动变量。
---
- name: Download repo
hosts: localhost
gather_facts: yes
roles:
- role: repodownload
tags:
- repodownload
- name: Starting Deployment of Application to tomcat nodes
hosts: '{{ target_env }}'
become: yes
become_user: tomcat
become_method: sudo
gather_facts: yes
roles:
- role: stoptomcat
tags:
- stoptomcat另一种方法是将become从play level中删除,并添加到角色stoptomcat中。像下面这样的东西应该可以工作。
---
- name: Starting Deployment of Application to tomcat nodes
hosts: '{{ target_env }}'
gather_facts: yes
roles:
- role: repodownload
tags:
- repodownload
- role: stoptomcat
become: yes
become_user: tomcat
become_method: sudo
tags:
- stoptomcat还没有测试代码,所以如果有任何格式化问题,我很抱歉。
https://stackoverflow.com/questions/61772996
复制相似问题