반환 값

반환 값 (Return Values)

Ansible 모듈은 실행 결과를 데이터 구조로 돌려줘요. 이 값은 변수에 레지스터(register)하거나 ansible 프로그램이 출력할 때 직접 볼 수 있어요. 이 문서는 모든 모듈에 공통으로 적용되는 반환 값을 다뤄요. 각 모듈 고유의 반환 값은 ansible-doc이나 공식 문서 사이트에서 확인할 수 있어요.

출처: 문서

본문

Ansible 모듈은 보통 변수에 레지스터할 수 있는 데이터 구조를 반환하며, ansible 프로그램이 출력할 때도 직접 볼 수 있어요. 각 모듈은 고유한 반환 값(ansible-doc과 공식 문서 사이트에서 확인 가능)을 선택적으로 문서화할 수 있어요.

이 문서는 모든 모듈에 공통인 반환 값을 다뤄요.

참고: 이 키 중 일부는 Ansible이 모듈의 반환 정보를 처리한 뒤 스스로 설정할 수도 있어요.

공통 (Common)

backup_file

파일을 조작할 때 backup=no|yes를 구현한 모듈에서, 원래 파일이 변경되었다면 생성된 백업 파일의 경로를 담아요.

"backup_file": "./foo.txt.32729.2020-07-30@06:24:19~"

changed

태스크가 대상 호스트나 위임된 호스트를 변경해야 했는지를 나타내는 불리언이에요.

"changed": true

diff

이전 상태와 현재 상태의 차이에 대한 정보예요. 보통 beforeafter 항목을 담은 딕셔너리이며, 콜백 플러그인이 diff 뷰로 포맷해요.

"diff": [
        {
            "after": "",
            "after_header": "foo.txt (content)",
            "before": "",
            "before_header": "foo.txt (content)"
        },
        {
            "after_header": "foo.txt (file attributes)",
            "before_header": "foo.txt (file attributes)"
        }
]

failed

태스크가 실패했는지 여부를 나타내는 불리언이에요.

"failed": false

invocation

모듈이 어떻게 호출되었는지에 대한 정보예요.

"invocation": {
        "module_args": {
            "_original_basename": "foo.txt",
            "attributes": null,
            "backup": true,
            "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
            "content": null,
            "delimiter": null,
            "dest": "./foo.txt",
            "directory_mode": null,
            "follow": false,
            "force": true,
            "group": null,
            "local_follow": null,
            "mode": "666",
            "owner": null,
            "regexp": null,
            "remote_src": null,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "src": "/Users/foo/.ansible/tmp/ansible-tmp-1596115458.110205-105717464505158/source",
            "unsafe_writes": null,
            "validate": null
        }
}

msg

사용자에게 전달되는 일반적인 메시지를 담은 문자열이에요.

"msg": "line added"

rc

일부 모듈은 커맨드라인 유틸리티를 실행하거나(raw, shell, command 등) 명령을 직접 실행하도록 설계됐어요. 이 필드는 그런 유틸리티의 '반환 코드(return code)'를 담아요.

"rc": 257

results

이 키가 존재하면 태스크에 루프가 있었다는 뜻이에요. 항목별로 일반적인 모듈 '결과(result)'의 목록을 담아요.

"results": [
    {
        "ansible_loop_var": "item",
        "backup": "foo.txt.83170.2020-07-30@07:03:05~",
        "changed": true,
        "diff": [
            {
                "after": "",
                "after_header": "foo.txt (content)",
                "before": "",
                "before_header": "foo.txt (content)"
            },
            {
                "after_header": "foo.txt (file attributes)",
                "before_header": "foo.txt (file attributes)"
            }
        ],
        "failed": false,
        "invocation": {
            "module_args": {
                "attributes": null,
                "backrefs": false,
                "backup": true
            }
        },
        "item": "foo",
        "msg": "line added"
    },
    {
        "ansible_loop_var": "item",
        "backup": "foo.txt.83187.2020-07-30@07:03:05~",
        "changed": true,
        "diff": [
            {
                "after": "",
                "after_header": "foo.txt (content)",
                "before": "",
                "before_header": "foo.txt (content)"
            },
            {
                "after_header": "foo.txt (file attributes)",
                "before_header": "foo.txt (file attributes)"
            }
        ],
        "failed": false,
        "invocation": {
            "module_args": {
                "attributes": null,
                "backrefs": false,
                "backup": true
            }
        },
        "item": "bar",
        "msg": "line added"
    }
    ]

skipped

태스크가 건너뛰어졌는지 여부를 나타내는 불리언이에요.

"skipped": true

stderr

일부 모듈은 커맨드라인 유틸리티를 실행하거나(raw, shell, command 등) 명령을 직접 실행하도록 설계됐어요. 이 필드는 그런 유틸리티의 오류 출력을 담아요.

"stderr": "ls: foo: No such file or directory"

stderr_lines

stderr가 반환되면 이 필드도 항상 제공돼요. 원래 출력의 줄 하나당 문자열 하나를 담은 목록이에요.

"stderr_lines": [
        "ls: doesntexist: No such file or directory"
        ]

stdout

일부 모듈은 커맨드라인 유틸리티를 실행하거나(raw, shell, command 등) 명령을 직접 실행하도록 설계돼요. 이 필드는 그런 유틸리티의 일반적인 출력을 담아요.

"stdout": "foo!"

stdout_lines

stdout이 반환되면 Ansible은 항상 문자열 목록을 제공하는데, 원래 출력의 줄 하나당 항목 하나를 담아요.

"stdout_lines": [
"foo!"
]

내부 사용 (Internal use)

이 키는 모듈이 추가할 수는 있지만 레지스터된 변수에서는 제거돼요. Ansible 자체가 '소비'하기 때문이에요.

ansible_facts

이 키는 호스트에 할당된 팩트(facts)에 추가될 딕셔너리를 담아야 해요. 이 값들은 직접 접근할 수 있으며 레지스터된 변수를 쓸 필요가 없어요.

exception

이 키는 모듈에서 예외가 발생했을 때의 traceback 정보를 담을 수 있어요. 높은 verbosity(-vvv)에서만 표시돼요.

warnings

이 키는 사용자에게 보여줄 문자열 목록을 담아요.

deprecations

이 키는 사용자에게 보여줄 딕셔너리 목록을 담아요. 딕셔너리의 키는 msg와 version이고 값은 문자열이며, version 키의 값은 빈 문자열일 수 있어요.

더 알아보기 (Learn more)

  • 기존 컬렉션, 모듈, 플러그인을 둘러보려면 컬렉션 인덱스를 확인해요.
  • 핵심·추가 모듈의 소스를 보려면 GitHub modules 디렉토리를 참고해요.
  • 질문이나 도움이 필요하면 Ansible 커뮤니케이션 가이드를 방문해 보세요.