【发布时间】:2020-08-17 13:31:23
【问题描述】:
我是 Makefile 的新手。这是我在 Makefile 中 ansible 的 PHONY 目标
.PHONY: healthcheck-webproxy
healthcheck-webproxy:
ansible-playbook -i inventory.py -e "env=dev" -e "group=webproxy" -e "command='curl -k
-s https://localhost:${nginx_https_port}/healthcheck'" site.yaml --
limit=vm4node.lite.com -bv
当我运行 make healthcheck-webproxy 时,它会跳过 ${nginx_https_port}
我得到了下面的 ansible adhoc
$make healthcheck-webproxy
ansible-playbook -i inventory.py -e "env=dev" -e "group=webproxy" -e "command='curl -k -s https://localhost:/healthcheck'" limit=vm4node.lite.com -bv
有人可以帮我解决这个问题吗?我不想让 makefile 跳过 ${nginx_https_port} 任何帮助将不胜感激。
我想在这里添加代码。
- hosts: "{{ env }}"
gather_facts: false
become: true
become_method: sudo
tasks:
- name: Check HealthService
shell: docker exec {{ container_name }} sh -c {{ command | quote }}
在 Shell 中它应该以这种方式执行。
#docker exec webproxy sh -c 'curl -k -s https://localhost:${nginx_https_port}/healthcheck'
【问题讨论】:
-
nginx_https_port是否应该是一个 environment 变量?编写的规则将尝试将其解释为make变量。您可以通过将$加倍以将其转义为make来解决此问题。或者,您可以在 makefile 或make命令行中为其指定一个值(作为make变量)。 -
@JohnBollinger 如果它是一个环境变量,它将作为一个 make 变量导入到 GNU make 中,所以这会起作用。
-
Make 不是“跳过”该变量:它正在扩展该变量并且该变量没有值,因此如您所见,它被扩展为空字符串。您需要将该变量设置为某个值。应该设置在哪里?你的makefile中还有其他地方应该设置它吗?是否应该在命令行上设置(
make nginx_https_port=8888)?在我们提供帮助之前,您必须提供更多信息,因为 makefile 的上述部分没有告诉我们。 -
是的,它是环境变量。
-
是的,它是环境变量。我没有定义变量..它应该从指定的容器中获取它。我试过localhost:$${nginx_https_port}/healthcheck 和localhost:$(${nginx_https_port})/它们都不起作用。
标签: ansible ansible-2.x makefile