Makefile 为ansible skips设计的虚假目标$

Makefile 为ansible skips设计的虚假目标$,makefile,ansible,ansible-2.x,makefile-errors,Makefile,Ansible,Ansible 2.x,Makefile Errors,我不熟悉Makefile。这是我在Makefile中为ansible设定的虚假目标 .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_

我不熟悉Makefile。这是我在Makefile中为ansible设定的虚假目标

.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
当我运行
makehealthcheckwebproxy
时,它跳过${nginx\u https\u port} 我得到下面的答案

$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\u https\u 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-shttps://localhost:${nginx\u https\u port}/healthcheck'

您需要在makefile中转义
$
。将
${nginx\u https\u port}
转换为
\${nginx\u https\u port}

makefile中的字符串是:

“command='curl-k-shttps://localhost:${nginx\u https\u port}/healthcheck'

因为它是一个用双引号括起来的字符串,所以会发生变量替换/扩展。因此,
${nginx\u https\u port}
在makefile中展开,在makefile运行的主机上。为了防止这种情况发生,您需要对$进行转义,以便将字符串按原样加载到ansible中

在单引号字符串(例如“echo$hello”)中,不会发生变量替换/扩展,这也是docker exec(在shell上执行)适用于您的原因:

docker exec webproxy sh-c'curl-k-shttps://localhost:${nginx\u https\u port}/healthcheck'


这里是字符串
curl-k-shttps://localhost:${nginx\u https\u port}/healthcheck'
按原样提供给docker容器中的sh,然后在其中执行它而不使用任何引号,并且可以扩展变量。

是否有可能假定nginx\u https\u port是环境变量?编写的规则将尝试将其解释为
make
变量。您可以通过加倍
$
将其转义到
make
来修复此问题。或者,您可以在makefile中或在
make
命令行中为它指定一个值(作为
make
变量)。@JohnBollinger如果它是一个环境变量,它会作为make变量导入GNU make,因此这会起作用。make不是“跳过”该变量:它正在扩展该变量,而该变量没有值,因此它被扩展为空字符串,如您所见。您需要将该变量设置为某个值。它应该放在哪里?您的makefile中还有其他地方应该设置它吗?是否应该在命令行上设置它(
make nginx\u https\u port=8888
)?在我们提供帮助之前,您必须提供更多信息,因为生成文件的上述部分没有告诉我们。是的,它是env variable。是的,它是env variable。我没有定义变量。。它应该从指定的容器中获取。我试过使用{nginx_https_port}/healthcheck和{nginx_https_port})/它们都不起作用。