Ansible 为什么条件反射不起作用?
我试图在Ansible中编写一个简单的条件语句,但遇到了一个错误Ansible 为什么条件反射不起作用?,ansible,Ansible,我试图在Ansible中编写一个简单的条件语句,但遇到了一个错误 - name: Add user key to AWS ec2_key: name: "{{ ansible_user_id }}_key" key_material: "{{ item }}" region: "{{ region }}" with_file: ~/.ssh/id_rsa.pub when: "development" == prefix 错误 我试过几种变体。这应该很直截了
- name: Add user key to AWS
ec2_key:
name: "{{ ansible_user_id }}_key"
key_material: "{{ item }}"
region: "{{ region }}"
with_file: ~/.ssh/id_rsa.pub
when: "development" == prefix
错误
我试过几种变体。这应该很直截了当,但我显然遗漏了一些东西。任何提示都将不胜感激。为了解决问题,我将脚本更新为
- name: Add user key to AWS
ec2_key:
name: "{{ ansible_user_id }}_key"
key_material: "{{ item }}"
region: "{{ region }}"
with_file: "~/.ssh/id_rsa.pub"
when: prefix == "development"
我还需要将
和\u file
放在双引号中,因为它以一个特殊字符开头。您尝试过交换变量和字符串吗?例如,prefix==“development”
。当:development==“prefix”看起来你也很受欢迎时,你是否做了。(您更改了一些内容,并将修复归因于其中一项)是的,部分更改来自@Daniel LeYou's you's missing point。你不能自信地说是哪种改变解决了问题。
- name: Add user key to AWS
ec2_key:
name: "{{ ansible_user_id }}_key"
key_material: "{{ item }}"
region: "{{ region }}"
with_file: "~/.ssh/id_rsa.pub"
when: prefix == "development"