ansible에서 - name: get cdp cisco.nxos.nxoscommand: command: - show cdp neigh register:…
- User
ansible에서
- name: get cdp cisco.nxos.nxos_command: command: - show cdp neigh register: output_cdp
이렇게 코드가 있을때 에러가 발생하면 output_cdp 값에 none이라는 문자열을 입력하는 코드 만들어 줘
Assistant
Ansible 코드 수정하여 에러 발생 시
output_cdp변수에 'none' 문자열 할당Ansible에서 특정 task 수행 중 에러가 발생했을 때, 해당 task의 결과를 등록하는 변수에 특정 값을 할당하도록 하는 방법은
ignore_errors키워드와failed_when조건을 사용하는 것입니다. 아래는 주어진 코드에 이를 적용한 예시입니다.- name: Get CDP neighbors cisco.nxos.nxos_command: commands: - show cdp neigh register: output_cdp ignore_errors: true - name: Handle error in CDP command set_fact: output_cdp: "none" when: output_cdp is defined and output_cdp.failed - name: Display output_cdp debug: msg: "{{ output_cdp }}"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.