2017-01-10 2 views
1

조건부로 Anonymous 역할을 실행하고 싶습니다. 즉, 일부 바이너리가 존재하지 않는 경우에만 (특정 앱 설치가 없다는 것을 의미합니다).조건부 역할 포함이 불안정합니다.

사용 패턴과 같은 것 here.

내 작전에 다음 코드를 사용 :

PLAY *************************************************************************** 

TASK [setup] ******************************************************************* 
ok: [my_host ] 

TASK [ myconditional_role : create temporary installation directory] *********************** 
fatal: [my_host]: FAILED! => {"failed": true, "msg": "ERROR! The conditional check 'myapp_exists|failed' failed. The error was: ERROR! |failed expects a dictionary"} 

왜 조건 검사가 실패 :

여기
- hosts: my_host 

    tasks: 
     - name: check app existence 
     command: /opt/my_app/somebinary 
     register: myapp_exists 
     ignore_errors: yes 

    roles: 
     - { role: myconditional_role, when: myapp_exists|failed } 
     - another_role_to_be_included_either_way 

출력입니까?

BTW

Ubuntu 16.04.01ansible 2.0.0.2 사용 : "임시 설치 디렉토리를 생성"을 조건부로 포함 역할의 첫 번째 주요 업무의 이름입니다.

답변

2

작업은 역할 이후에 으로 실행되므로 myapp_exists은 정의되지 않습니다.
대신 pre_tasks을 사용하십시오.

또한 when은 실제로 조건부 역할이 아니며이 when 문을 역할의 모든 작업에만 첨부한다는 점에 유의하십시오.

+0

그렇다면 특정 사용 사례에 대한 조건부 역할 포함을위한 제안 된 패턴은 무엇입니까? – pkaramol

+1

역할의 main.yml 작업 파일 내부에서 테스트를 이동하고 필요할 경우 install.yml을 포함합니다. –

관련 문제