다음 과 같은 mosh_version
ansible debug msg
명령을 사용하여 이전에 등록 된 변수 를 인쇄하려고합니다 .
- name: Print mosh version
debug: msg="Mosh Version: {{ mosh_version.stdout }}"
작동하지 않고 다음 오류를 인쇄합니다.
Note: The error may actually appear before this position: line 55, column 27
- name: Print mosh version
debug: msg="Mosh Version: {{ mosh_version.stdout }}"
^
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
나는 시도했다
- name: Print mosh version
debug: msg=Mosh Version: "{{ mosh_version.stdout }}"
그러나 이것은 단지 “Mosh”를 인쇄 할 것입니다.
이것을 실행하는 가장 좋은 방법은 무엇입니까?
답변
이 시도:
- name: Print mosh version
debug: "msg=Mosh Version: '{{ mosh_version.stdout }}'"
http://docs.ansible.com/YAMLSyntax.html#gotchas의 추가 정보
편집 : 이와 같은 것이 나에게 완벽하게 작동합니다.
- name: Check Ansible version
command: ansible --version
register: ansibleVersion
- name: Print version
debug:
msg: "Ansible Version: {{ ansibleVersion.stdout }}"
답변
가장 간단한 답변
- debug: var=mosh_version.stdout
답변
콜론을 제거하십시오.
debug: msg="Mosh Version {{ mosh_version.stdout }}"
답변
나는 이것을 사용한다. 큰 따옴표 ( “)와 작은 따옴표 ( ‘)의 위치를 주목하라
- name: Print mosh version
debug: "msg='Mosh Version: {{ mosh_version.stdout }}'"
답변
Ansible strings / cmds의 특수 문자에 문제가있을 때마다 다음과 같이하십시오.
- 작은 따옴표로 감싸십시오.
- 이중 중괄호로 감싸십시오.
표준 콜론은 {{':'}}
그리고 당신의 임무는 다음과 같습니다.
- debug: msg="Ansible Version{{':'}} {{ ansibleVersion.stdout }}"
다시 말하지만 대부분의 특수 문자, 심지어 문자열에서도 작동합니다. 다음을 고려하세요:
docker ps --format '{{.Names}}'
이를 Ansible에서 실행하려면 동일한 논리를 적용하면 다음 작업이 예상대로 실행됩니다.
- name: Get the docker container names
become: yes
shell: "docker ps --format '{{'{{'}}.Names{{'}}'}}'"
register: docker_containers