실행할 작업을 필터링하는 데 사용할 --tags
때 사용하는 습관 ansible-playbook
이 있습니다. 최근에 Ansible 2.7에서 2.9로 전환했습니다 (큰 격차, 어?).
를 사용할 때 ansible이 독점적으로 사실을 수집하지 않은 것에 놀랐습니다 --tags
. 그리고 내가 좋아하는 GitHub의 폐쇄 여러 유사한 경우 본 이 하나 또는 이 일을 . 2.8 버전부터 ansible에 영향을 미치는 것으로 보이지만 해결 된 것으로 표시됩니다. 누구든지이 행동을 확인할 수 있습니까? 2.8에서 발생하는 것 같습니다.
ANSIBLE 버전 :
ansible --version
ansible 2.9.9.post0
config file = None
configured module search path = [u'/opt/ansible/ansible/library']
ansible python module location = /opt/ansible/ansible/lib/ansible
executable location = /opt/ansible/ansible/bin/ansible
python version = 2.7.6 (default, Nov 13 2018, 12:45:42) [GCC 4.8.4]
ANSIBLE 구성 :
ansible-config dump --only-changed
DEFAULT_MODULE_PATH(env: ANSIBLE_LIBRARY) = [u'/opt/ansible/ansible/library']
재현 단계 :
플레이 북 test.yml :
- name: First test
hosts: localhost
connection: local
gather_facts: yes
roles:
- { role: test, tags: test }
tags: first
- name: Second test
hosts: localhost
connection: local
gather_facts: yes
roles:
- { role: test, tags: test }
tags: second
역할 : roles / test / tasks / main.yml
- debug:
msg: System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}
ansible-playbook test.yml --check
= 오류가 없습니다.
ansible-playbook test.yml --check --tags "test"
= 실패 : 1
"작업에 변수가 정의되지 않은 옵션이 있습니다. 오류 : 'ansible_product_uuid'is undefined [...]"
그리고 출력에서 사실이 수집되지 않았 음을 알 수 있습니다.
음, 플레이 레벨에 태그가있을 때 의도 된 행동 인 것 같습니다.
이것은 의도 된 동작입니다. 태그로 연극에 태그를 지정하면 해당 태그가
gather_facts
단계always
에 적용되고 기본적으로 적용되는 태그가 제거 됩니다. 플레이에 태그를 지정하는 것이 목표 인 경우setup
팩트를 수집하기 위해 태그가 있는 작업을 추가 할 수 있습니다 .
samdoran이 2019 년 6 월 11 일에 댓글 을 작성 함
유의하시기 바랍니다 다음, 역할의 사용에 연결되지가 단순히 수행하여 재현 할 수있는이,이다 :
- name: First test
hosts: all
tags:
- first
tasks:
- debug:
msg: System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}
tags: test
실패한 요약을 생성합니다.
$ ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook play.yml --tags "test"
PLAY [First test] *************************************************************************************************
TASK [debug] ******************************************************************************************************
fatal: [localhost]: FAILED! => {}
MSG:
The task includes an option with an undefined variable. The error was: 'ansible_product_uuid' is undefined
The error appears to be in '/ansible/play.yml': line 7, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- debug:
^ here
PLAY RECAP ********************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
따라서 플레이 레벨의 태그를 제거하거나 setup
메시지에 따라 모듈을 사용해야합니다 .
이는 역할 내에서 수행 할 수 있으므로 역할은 설정할 수없는 변수에 의존하지 않습니다.
role / test / tasks / main.yml 역할이 주어 집니다.
- setup:
- debug:
msg: System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}
그리고 플레이 북 :
- name: First test
hosts: all
tags:
- first
roles:
- role: test
tags:
- test
- name: Second test
hosts: all
tags:
- second
roles:
- role: test
tags:
- test
다음은 실행 및 요약입니다.
$ ansible-playbook play.yml --tags "test"
PLAY [First test] *************************************************************************************************
TASK [test : setup] ***********************************************************************************************
ok: [localhost]
TASK [test : debug] ***********************************************************************************************
ok: [localhost] => {
"msg": "System localhost has uuid 3fc44bc9-0000-0000-b25d-bf9e26ce0762"
}
PLAY [Second test] ************************************************************************************************
TASK [test : setup] ***********************************************************************************************
ok: [localhost]
TASK [test : debug] ***********************************************************************************************
ok: [localhost] => {
"msg": "System localhost has uuid 3fc44bc9-0000-0000-b25d-bf9e26ce0762"
}
PLAY RECAP ********************************************************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
이 모든 것은 다음에서 실행됩니다.
ansible 2.9.9
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.8/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.3 (default, May 15 2020, 01:53:50) [GCC 9.3.0]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다