웹 서비스 용 배포 가이드를 만듭니다. 각 웹 서비스는 다음과 같은 자신의 디렉토리에 있습니다 :Ansible - 여러 디렉토리가 있는지 확인 - 각 디렉토리에서 스크립트를 실행하는 경우 - 어떻게?
/webapps/service-one/
/webapps/service-two/
/webapps/service-three/
내가 서비스 디렉토리가 존재하는지 확인하려면, 그렇다면, 나는 정상적으로 서비스를 중지 쉘 스크립트를 실행합니다. 현재 ignore_errors: yes
을 사용하여이 단계를 완료 할 수 있습니다.
- name: Stop services
with_items: services_to_stop
shell: "/webapps/scripts/stopService.sh {{item}}"
ignore_errors: yes
이 방법이 효과가 있지만 디렉토리 중 하나가 존재하지 않거나 서비스가 처음으로 배포되는 경우 출력이 매우 혼란 스럽습니다. 나는 효과적으로 이들 중 하나 같은 것을 원하는 :
이 :
- name: Stop services
with_items: services_to_stop
shell: "/webapps/scripts/stopService.sh {{item}}"
when: shell: [ -d /webapps/{{item}} ]
나이 :
- name: Stop services
with_items: services_to_stop
shell: "/webapps/scripts/stopService.sh {{item}}"
stat:
path: /webapps/{{item}}
register: path
when: path.stat.exists == True
jinja 필터링, 특히 map() 및 목록 필터를 사용하는 것이 좋습니다. 이전에 보지 못했던 방식입니다. –
이것은 내가 찾고있는 것에 꽤 상상합니다. 감사! – R4F6