[Ansible] 02. ad-hoc Command 간단 예제

Date:     Updated:

카테고리:

태그:

[Ansible] 02. ad-hoc Command 간단 예제


🔔 Ansible ad-hoc(애드혹) 명령어

ansible adhoc 명령은 playbook 을 작성하지 않고 command-line 에서 직접 앤서블 모듈을 호출해서 실행하는 방식

자세한 내용 (1) : https://docs.ansible.com/ansible/latest/command_guide/intro_adhoc.html

자세한 내용 (2) : https://docs.ansible.com/ansible/latest/collections/ansible/builtin/index.html#modules

예제 Github : https://github.com/revenge1005/Ansible_study

(a) 📜 dnf update

# becom : sudo 권한을 실행
# ask-become-pass : pw 입력

$ ansible all -m dnf -a update_cache=true --become --ask-become-pass
BECOME password:
node01 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "msg": "Cache updated",
    "rc": 0,
    "results": []
}
node02 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "msg": "Cache updated",
    "rc": 0,
    "results": []
}


(b) 📜 Managed 노드 Nginx 설치 및 Nginx 실행

$ ansible all -m dnf -a name=nginx --become --ask-become-pass

$ ansible all -m service -a "name=nginx state=started enabled=yes" --become --ask-become-pass


(c) 📜 get_url module

$ ansible all -m get_url -a "url=https://download.java.net/openjdk/jdk8u41/ri/openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz dest=/home/choi"
node01 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": true,
    "checksum_dest": null,
    "checksum_src": "3bf29d9bc379f18dab24358e8bd97c4340ce3f1a",
    "dest": "/home/choi/openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz",
    "elapsed": 6,
    "gid": 1000,
    "group": "choi",
    "md5sum": "35f515e9436f4fefad091db2c1450c5f",
    "mode": "0664",
    "msg": "OK (174287938 bytes)",
    "owner": "choi",
    "size": 174287938,
    "src": "/home/choi/.ansible/tmp/ansible-tmp-1643300466.165444-11834-5022500933289/tmpyct9v784",
    "state": "file",
    "status_code": 200,
    "uid": 1000,
    "url": "https://download.java.net/openjdk/jdk8u41/ri/openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz"
}

...

$ ansible all -m shell -a "ls -l /home/choi"
node01 | CHANGED | rc=0 >>
total 170204
-rw-rw-r-- 1 root root 174287938 Jan 28 01:21 openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz


ANSIBLE 카테고리 내 다른 글 보러가기

댓글 남기기