사용자 도구

사이트 도구


devops:ansible

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
devops:ansible [2021/05/17 18:21]
kwon37xi
devops:ansible [2023/01/14 13:38] (현재)
kwon37xi [lineinfile module]
줄 6: 줄 6:
   * [[https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html|Best Practices — Ansible Documentation]]   * [[https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html|Best Practices — Ansible Documentation]]
   * 자동화 툴   * 자동화 툴
 +
 +===== Ubuntu PPA =====
 +  * https://launchpad.net/~ansible/+archive/ubuntu/ansible
 +
 +<code sh>
 +sudo add-apt-repository ppa:ansible/ansible
 +</code>
  
 ===== AWS ===== ===== AWS =====
줄 110: 줄 117:
 ===== shell & command ===== ===== shell & command =====
   * [[https://www.mydailytutorials.com/introduction-shell-command-module-ansible/|Introduction to Shell and Command Modules in Ansible - My Daily Tutorials]]   * [[https://www.mydailytutorials.com/introduction-shell-command-module-ansible/|Introduction to Shell and Command Modules in Ansible - My Daily Tutorials]]
 +  * [[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html|ansible.builtin.command]]
 +    * ''command''는 명령만 실행할 뿐 셸을 띄우지 않기 때문에 환경변수 등이 주입이 안된다.
 +  * [[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/shell_module.html|ansible.builtin.shell]]
 +    * 기본 ''/bin/sh'' 를 띄워 명령을 실행한다. [[linux:bash|Bash]] 등으로 강제로 바꿔야 올바로 작동하는 명령들도 있을 수 있으므로 그 때는 ''args.executable: /bin/bash''로 셸을 변경해줘야 한다.
  
 ===== apt repository ===== ===== apt repository =====
줄 133: 줄 144:
 </code> </code>
  
-===== include tasks =====+===== include / import ===== 
 +  * [[https://docs.ansible.com/ansible/2.8/user_guide/playbooks_reuse.html|Creating Reusable Playbooks — Ansible Documentation]] 
 +  * [[https://docs.ansible.com/ansible/2.8/user_guide/playbooks_reuse_includes.html#playbooks-reuse-includes|Including and Importing — Ansible Documentation]] 
 +  * [[https://docs.ansible.com/ansible/2.8/modules/list_of_utilities_modules.html#utilities-modules|Utilities modules — Ansible Documentation]] 
 +  * ''include*'' 는 동적(dynamic)이다. 일부 기능이 작동하지 않는다(''--start-at-task''같은). 실행시점 해석. 
 +  * ''import*'' 는 정적(static)이다. 설정파일 읽을 때 해석.
   * [[https://stackoverflow.com/questions/58772082/can-i-include-multiple-tasks-in-include-tasks-from-tasks-main-yml|ansible - Can I include multiple tasks in include_tasks from tasks/main.yml? - Stack Overflow]]   * [[https://stackoverflow.com/questions/58772082/can-i-include-multiple-tasks-in-include-tasks-from-tasks-main-yml|ansible - Can I include multiple tasks in include_tasks from tasks/main.yml? - Stack Overflow]]
  
 +===== Linux System Roles  =====
 +  * [[https://github.com/linux-system-roles|linux-system-roles]]
 +  * https://github.com/linux-system-roles
 +
 +===== shell completion =====
 +  * https://docs.ansible.com/ansible/devel/installation_guide/intro_installation.html#shell-completion
 +<code sh>
 +sudo apt install python3-argcomplete
 +</code>
 +  * 아래 항목을 ''.bashrc'' 에 넣는다 배포판에 따라 ''register-python-argcomplete''(''3'' 제외)일 수도 있음. (전역 설정도 가능함)
 +<code sh>
 +# 필히 "" 로 감싸야한다.
 +eval "$(register-python-argcomplete3 ansible)"
 +eval "$(register-python-argcomplete3 ansible-config)"
 +eval "$(register-python-argcomplete3 ansible-console)"
 +eval "$(register-python-argcomplete3 ansible-doc)"
 +eval "$(register-python-argcomplete3 ansible-galaxy)"
 +eval "$(register-python-argcomplete3 ansible-inventory)"
 +eval "$(register-python-argcomplete3 ansible-playbook)"
 +eval "$(register-python-argcomplete3 ansible-pull)"
 +eval "$(register-python-argcomplete3 ansible-vault)"
 +
 +</code>
 +
 +===== lineinfile module =====
 +  * [[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html|lineinfile module]]
 +  * 파일 내의 줄들을 관리한다. 내용을 추가하거나, 변경하거나.
 +  * [[linux:sed|Linux sed]] 대체.
 +
 +=====  =====
 +  * [[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/blockinfile_module.html|blockinfile module]]
 +  * 파일 내의 특정 블록을 추가,사제,변경한다.
 +===== replace module =====
 +  * [[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/replace_module.html|replace module]]
 +  * [[:regex|RegEx]]로 파일 내용 교체
 ===== 참조 ===== ===== 참조 =====
   * [[https://www.youtube.com/playlist?list=PLT98CRl2KxKEUHie1m24-wkyHpEsa4Y70|Getting started with Ansible - YouTube]] : 매우 쉽게 Ansible 설명.   * [[https://www.youtube.com/playlist?list=PLT98CRl2KxKEUHie1m24-wkyHpEsa4Y70|Getting started with Ansible - YouTube]] : 매우 쉽게 Ansible 설명.
줄 143: 줄 194:
   * [[http://theeye.pe.kr/archives/2597|Ansible Playbook 정리 | 아이군의 블로그]]   * [[http://theeye.pe.kr/archives/2597|Ansible Playbook 정리 | 아이군의 블로그]]
   * [[https://www.ansible.com/blog/ansible-tips-and-tricks-dealing-with-unreliable-connections-and-services|Ansible Tips and Tricks: Dealing with Unreliable Connections and Services]]   * [[https://www.ansible.com/blog/ansible-tips-and-tricks-dealing-with-unreliable-connections-and-services|Ansible Tips and Tricks: Dealing with Unreliable Connections and Services]]
 +  * [[https://www.lesstif.com/ansible/windows-ansible-95879887.html|Windows 에 Ansible 설치하기]]
devops/ansible.1621243315.txt.gz · 마지막으로 수정됨: 2021/05/17 18:21 저자 kwon37xi