0
터미널 호스트에 서비스가 있는지 확인하고 싶습니다.서비스가 Ansible에 있는지 확인하는 방법은 무엇입니까?
그래서 방금 플레이 북을 아래와 같이 작성했습니다.
---
- hosts: '{{ host }}'
become: yes
vars:
servicename:
tasks:
- name: Check if Service Exists
stat: 'path=/etc/init.d/{{ servicename }}'
register: servicestatus
with_items: '{{ servicename }}'
- name: Show service service status
debug:
msg: '{{ servicename }} is exists.'
with_items: '{{ servicename }}'
when: servicestatus.stat.exists
그런 다음이 플레이 북을 이미 Nginx를 실행중인 호스트에 실행하려고합니다.
ansible-playbook cheknginxservice.yml -i /etc/ansible/hosts -e 'host=hostname' -e 'servicename=nginx'
그리고 나는 이와 같은 오류가 발생했습니다.
FAILED! => {"failed": true, "msg": "The conditional check 'servicestatus.stat.exists' failed. The error was: error while evaluating conditional (servicestatus.stat.exists): 'dict object' has no attribute 'stat'\n\nThe error appears to have been in '/home/centos/cheknginxservice.yml': line 13, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n with_items: '{{ servicename }}'\n - name: Show service servicestatus\n ^here\n"}
to retry, use: --limit @/home/centos/cheknginxservice.retry
따라서 문제는 관련된 조건을 사용할 때 통계 모듈에 관한 것입니다.
감사합니다. 나는 정확히 "with_items"가 정확히 무엇인지 모릅니다. 그래서, 나는 이전의 작업에서 많은 시간을 사용합니다. –
나는 호스트 터미널에서 "apt-get remove nginx"명령을 사용하여 nginx 서비스를 제거하려고 시도합니다. 그러나 /etc/init.d에있는 "nginx"파일은 여전히 존재합니다. 그래서, 내 작업은 여전히 존재하는 출력을 가지고 있습니다. 책임자를 통해 존재하는 서비스를 확인하는 또 다른 방법이 있습니까? 감사. –
@TutchaponSirisaeng이 답변에 대한 업데이트를 참조하십시오. – helloV