

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 에서 조건부 구문 사용 AWSTOE
<a name="toe-conditional-constructs"></a>

조건부 구문은 지정된 조건부 표현식이 `true` 또는 `false`로 평가되는지 여부에 따라 구성 요소 문서에서 다양한 작업을 수행합니다. `if` 구문을 사용하여 구성 요소 문서의 실행 흐름을 제어할 수 있습니다.

## if 구문
<a name="toe-conditional-if"></a>

`if` 구문을 사용하여 단계를 실행해야 하는지 여부를 평가할 수 있습니다. 기본적으로 `if` 조건식이 `true`로 평가되면 AWSTOE 는 단계를 실행하고 조건이 `false`로 평가되면 AWSTOE 는 단계를 건너뜁니다. 단계를 건너뛰면 AWSTOE 가 단계와 문서가 성공적으로 실행되었는지 평가할 때 성공 단계로 처리됩니다.

**참고**  
단계가 재시작을 트리거하더라도 `if` 문은 한 번만 평가됩니다. 단계가 다시 시작되면 `if` 문이 이미 평가되었음을 인식하고 중단된 위치에서 계속됩니다.

### 구문
<a name="toe-conditional-if-syntax"></a>

```
if:
  - <conditional expression>:
      [then: <step action>]
      [else: <step action>]
```


| 키 이름 | 필수 | 설명 | 
| --- | --- | --- | 
| 조건식 | 예 |  조건식에는 최상위 수준에서 다음 유형의 연산자 중 정확히 하나가 포함될 수 있습니다. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/imagebuilder/latest/userguide/toe-conditional-constructs.html) 표현식이 여러 조건을 충족해야 하는 경우 논리 연산자를 사용하여 조건을 지정합니다.  | 
| then | 아니요 |  조건식이 `true`로 평가되는 경우 수행할 작업을 정의합니다.  | 
| else | 아니요 |  조건식이 `false`로 평가되는 경우 수행할 작업을 정의합니다.  | 
| 단계 작업 | 조건부 |  `then` 또는 `else`를 사용할 때는 다음 단계 작업 중 하나를 지정해야 합니다. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/imagebuilder/latest/userguide/toe-conditional-constructs.html)  | 

**예제 1: 패키지 설치**  
 AWSTOE 구성 요소 문서의 다음 예제 단계는 논리 연산자를 사용하여 파라미터 값을 테스트하고 패키지의 압축이 풀린 경우 적절한 패키지 관리자 명령을 실행하여 애플리케이션을 설치합니다.

```
    - name: InstallUnzipAptGet
      action: ExecuteBash
      if:
        and:
            - binaryExists: 'apt-get'
            - not:
                binaryExists: 'unzip'
      inputs:
        commands:
            - sudo apt-get update
            - sudo apt-get install -y unzip

    - name: InstallUnzipYum
      action: ExecuteBash
      if:
        and:
            - binaryExists: 'yum'
            - not:
                binaryExists: 'unzip'
      inputs:
        commands:
            - sudo yum install -y unzip

    - name: InstallUnzipZypper
      action: ExecuteBash
      if:
        and:
            - binaryExists: 'zypper'
            - not:
                binaryExists: 'unzip'
      inputs:
        commands:
            - sudo zypper refresh
            - sudo zypper install -y unzip
```

**예제 2: 단계 건너뛰기**  
다음 예제에서는 단계를 건너뛰는 두 가지 방법을 보여줍니다. 하나는 논리적 연산자를 사용하고 다른 하나는 `Skip` 단계 작업과 비교 연산자를 사용합니다.

```
# Creates a file if it does not exist using not
- name: CreateMyConfigFile-1
  action: ExecuteBash
  if:
    not:
      fileExists: '/etc/my_config'
  inputs:
    commands:
      - echo "Hello world" > '/etc/my_config'

# Creates a file if it does not exist using then and else
- name: CreateMyConfigFile-2
  action: ExecuteBash
  if:
    fileExists: '/etc/my_config'
    then: Skip
    else: Execute
  inputs:
    commands:
      - echo "Hello world" > '/etc/my_config'
```