홈>
vars/디렉토리에 다음 사전이 있습니다.
vars_dict.yml
---
ruleset:
rule1:
rule_name: testrule1
description: Test Rule number 1
source_zone: trust
destination_zone: untrust
source_ip: 1.2.3.4
source_user: any
destination_ip: 4.5.6.7
action: allow
disabled: FALSE
location: top
log_end: TRUE
tag_name: superimportant
vsys: vsys1
state: present
commit: TRUE
rule2:
rule_name: testrule2
description: Test Rule number 2
source_zone: trust
destination_zone: untrust
source_ip: 1.2.3.5
source_user: any
destination_ip: 4.5.6.8
action: allow
disabled: FALSE
location: bottom
log_end: TRUE
tag_name: superimportant
vsys: vsys1
state: present
commit: TRUE
...
또한 vars /에 이러한 지원 변수 파일이 있습니다 :
credentials.yml
fw_username: test
fw_password: test
와 fw.yml
fw_ip_address: 192.168.1.1
이 플레이 북을 사용하여 방화벽으로 명령을 보내기 위해 각 데이터 세트를 반복하고 싶습니다.
---
- hosts: localhost
connection: local
roles:
- role: PaloAltoNetworks.paloaltonetworks
tasks:
- name: include variables
include_vars:
dir: vars
- name: Add superimportant rules to the firewall
panos_security_rule:
ip_address: '{{ fw_ip_address }}'
username: '{{ fw_username }}'
password: '{{ fw_password }}'
rule_name: '{{ ruleset.rule_name }}'
description: '{{ ruleset.description }}'
source_zone: ['{{ ruleset.source_zone }}']
destination_zone: ['{{ ruleset.destination_zone }}']
source_ip: ['{{ ruleset.source_ip }}']
source_user: ['{{ ruleset.source_user }}']
destination_ip: ['{{ ruleset.destination_ip }}']
action: '{{ ruleset.action }}'
disabled: '{{ ruleset.disabled }}'
location: '{{ ruleset.location }}'
log_end: '{{ ruleset.log_end }}'
tag_name: '{{ ruleset.tag_name }}'
vsys: '{{ ruleset.vsys }}'
state: '{{ ruleset.state }}'
commit: '{{ ruleset.commit }}'
with_dict:
- "{{ ruleset }}"
...
어쩌면 기대했던 결과는 각 데이터 블록에 대해 다음과 같이 출력을 반복하여 생성하는 것입니다.
panos_security_rule:
ip_address: '192.168.1.1'
username: 'test'
password: 'test'
rule_name: 'Ansible test 1'
description: 'An Ansible test rule'
source_zone: ['trust']
destination_zone: ['untrust']
source_ip: ['1.2.3.4']
source_user: ['any']
destination_ip: ['any']
action: 'allow'
disabled: 'False'
location: 'top'
log_end: 'true'
tag_name: 'superimportant'
vsys: 'vsys1'
state: 'present'
commit: 'True'
내가받는 오류는
TASK [include variables] *****************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "Syntax Error while loading YAML.\n mapping values are not allowed here\n\nThe error appears to have been in '/root/ansible/vars/vars.yml': line 3, column 16, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n rule_name: testrule1\n description: Test Rule number 1\n ^ here\n"}
to retry, use: --limit @/root/ansible/panos_dynamic.retry
문서와 게시물을 읽었으며 사전 파일을 다시 포맷하고 with_items, with_dict를 사용하여 "{{}}"로 묶고 괄호없이 시도했는데 완전히 막힌 것 같습니다.
여기에 간단한 것이 빠졌습니까?
- 답변 # 1
관련 자료
- 문자열 열을 사용하여 SQL 테이블을 피벗하는 구문 오류
- glm ()을 사용하는 R의 로지스틱 회귀는 플로팅 할 때 xycoords에 오류를 생성합니다
- html - 웹 스크랩 핑 (Python 3) 코드에 구문 오류가 있습니까?
- r modelframedefault 오류 - lm을 사용할 때 객체가 행렬이 아닙니다
- php - 모든 요청에 JSON 구문 오류를 제공하는 WooCommerce API
- html - PHP에서 DOM을 사용하여 요소의 텍스트를 가져 오지만 오류를 반환합니다
- c++ - 방문자 사용시 변형 변환 오류 향상
- wordpress - $wpdb-> get_results ($wpdb-> prepare (… SQL 구문에 오류가 있습니다
- android - ViewModel을 사용하는 Jetpack Compose DataStore 오류,"Viewmodel에 인수 생성자가 없습니다"
- python - Pandas에는 현재 사용중인이 구문에 대한 대안이 있습니까?
- ubuntu - python - 간단한 for 루프 구문 오류
- ubuntu18.04 - apt 또는 apt-get 사용시 오류 메시지
- wordpress - 구문 분석 오류 - 250 행의 c : \ xampp \ htdocs \ attendancesystem \ resources \ php \ methodphp의 구문 오류, 예기치 않은 'echo'(t_ec
- java - 문자열 수식을 전달하여 ScriptEngineManager를 사용할 때 오류가 발생하는 이유는 무엇입니까?
- python - 사용자 지정 손실 함수 사용시 modelfit () 오류
- python - Pandas 데이터 프레임을 사용하여 CSV에서 테이블로 데이터를로드하는 동안 오류가 발생했습니다
- 입력을 위해 Python 생성기를 사용하는 동안 keras의 OOM 오류
- mysql - 오류 - er_parse_error : sql 구문에 오류가 있습니다 다중 삽입 용
- c++ - 헤더 파일에서 클래스 선언을 사용할 때 링커 오류
- google sheets - IFS 및 ARRAYFORMULA를 사용할 때 일치 없음 오류를 방지하는 방법
관련 질문
- ssh - Cisco DevNet CML Sandbox 장치에 대해 Ansible을 실행하는 데 문제가 있음
- ansible - 중첩 된 dict에 루프
- Ansible - Ansible- AWX 로그인 토큰 API
- yaml - 가능 - 쉘 명령에서 정의되지 않은 변수
- regex - regex_findall을 사용하여 출력 필터링
- yaml - Ansible 플레이 북 식별
- database - 작동하지만 Yaml 스크립트를 실행하면 구문 오류가 계속 발생합니다
- yaml - 변수에 값이있는 경우에만 Ansible 팩트를 설정할 수 있습니까?
- Ansible에서 변수 반복
- python - 조건이 만족되지 않을 때 작업을 건너 뛰는 방법
질문이 몇 가지 수정되어 질문을 해결할 수 있습니다.
먼저, dict 대신 목록을 사용하여 역할을 정의하십시오. 둘 다 작동하지만 목록은 약간 더 깔끔한 코드입니다.
두 번째with_dict
표기법은 작업 매개 변수가 아닌 작업과 동일한 수준으로 들여 쓰기해야합니다.마침내, 귀하의 질문은
ruleset
를 사용합니다 루프 변수로. 기본적으로 이것은item
입니다. 반복되는 list/dict 변수와 다른 것이 필요합니다.예 : vars_dict.yml
플레이 북 : --- -호스트 : localhost 연결 : 로컬