티스토리 뷰

IT/Ansible

[RHCSAA 교육 정리] 1 장 - 2장

트래이닝맨 2018. 3. 2. 07:03
728x90
반응형
1장
Ansible is Simple
Ansible is Powerful
Anslble is Agentless


Ansible's Automation Engine
- inventory
- API
- Modules
- Plugins

Ansible Way
- Complexity Kills Productivity
- Optimise For Readability
- Think Declaratively

최소 설치 요건(managed servers)
- 윈도우는 최소 Powershell 3.0 이상  필요
- Linux는 python 2.4 이상이고 만약 2.5 이하면 python-simplejson package도 설치되어 있어야함. 그리고 SELinux는 enable되어 있어야하고, libselinux-python 도 설치되어 있어야함.


유용한 명령어 모음

# 설치
sudo yum install -y python ansible

# Managed hosts 확인
ansible $GROUP_NAME -i $INVENTORY_NAME --list-hosts




2장

static inventory
A static inventory file is an INI-like text file that specifies the managed hosts that Ansible targets.

예제
[usa]
newyork1.example.com
newyork2.example.com

[canada]
milton01.example.com
milton02.example.com

[na:children]
canada
usa


짧게 구간을 정의하는 방법

192.168.[4:7].[0:255]  == 192.168.4.0/22 network  == 192.168.4.0 ~ 192.168.7.255

test[01:20].example.com == test01.example.com ~ test20.example.com.

[a:c].test.example.com == a.test.example.com, b.test.example.com c.test.example.com.

1001:ak8::[a:f] IPV6 addresses == 1001:ak8::a ~ 1001:ak8::f

Note:
all host group는 모든 host를 포함한다.
ungrouped  host group은 group안에 포함 안되는 모든 host를 포함함다.


Ansible 설정파일(Ansible.cfg 순서)

1. $ANSIBLE_CONFIG 
2. ./ansible.cfg
3. ~/ansible.cfg   (잘 안사용함)
4. /etc/ansible/ansible.cfg  (잘 안사용함)

어떤 ansible.cfg를 사용하는 확인하는 방법
 ansible --version

ansible servers --list-hosts -v

어떤 설정들을 할수 있는가?
$ grep "^\[" /etc/ansible/ansible.cfg
[defaults]
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[accelerate]
[selinux]

가장 많이 사용하는 설정들
[defaults]
inventory = ./inventory
remote_user = someuser
ask_pass = false

[privilege_escalation]
become = true
become_method = sudo
become_user = root
become_ask_pass = false


Privilege 가 필요한경우 유저를 sudoer에 추가
## password-less sudo for Ansible user
someuser ALL=(ALL) NOPASSWD:ALL


Window를 사용할때 아래설정 필요
ansible_connection: winrm
ansible_port: 5986


ssh key 복사하기
 ssh-copy-id root@test1.example.com

ssh key 복사하기 with ansible
- name: 공개키를 관리 호스트에 복사하기
  hosts: all

  tasks:
  - name: root's ~/.ssh/authorized_hosts 에 추가하기
        authorized_key:
         user: root
         state: present
         key: '{{ item }}'
    with_file:
         - ~/.ssh/id_rsa.pub

ansible_connect는 smart를 디폴트로 사용한다.
만약에 localhost 가 호스트로 오면
 - ssh 대신 local를 사용함
 - remote_user는 무시됨
 - become_user가 사용됨( 만약 become=true 면)


AD-HOC Commands

 ansible $HOST -m module [-a 'module argument']' -i $INVENTORY


Ansible Doc 사용법

ansible-doc ping
ansible-doc -l

옵션
-o : stdout을 찍어줌
-u : remote_user
-b : become, --become
-K : become_ask_pass, --ask-become-pass




반응형

'IT > Ansible' 카테고리의 다른 글

[RHCSAA 교육 정리] 9 장 - 12 장  (0) 2018.03.02
[RHCSAA 교육 정리] 7 장 - 8장  (0) 2018.03.02
[RHCSAA 교육 정리] 5 장 - 6장  (0) 2018.03.02
[RHCSAA 교육 정리] 3 장 - 4장  (0) 2018.03.02
[RHCSAA]앤서블 자격증  (3) 2018.03.02
댓글
250x250
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함