Ansible 실습


개요

Ansible 실습 1
Configuring Ubuntu with Ansible
scrapbook@148696c2f85b:~/tutorial$ cat myhosts 
[group1]
host01 ansible_ssh_user=ubuntu
scrapbook@148696c2f85b:~/tutorial$ ansible group1 -i myhosts -m command -a date
The authenticity of host 'host01 (172.17.0.13)' can't be established.
ECDSA key fingerprint is b3:80:9f:fd:ca:8b:65:b5:77:ab:09:2b:9c:2e:9d:bc.
Are you sure you want to continue connecting (yes/no)? yes
host01 | success | rc=0 >>
Mon Dec 20 07:58:09 UTC 2021
scrapbook@148696c2f85b:~/tutorial$ cat site.yml 
---
- hosts: host01
  become: true
  tasks:
  - name: ensure latest sysstat is installed
    apt:
      name: sysstat
      state: latest
scrapbook@148696c2f85b:~/tutorial$ ansible-playbook -i myhosts site.yml

PLAY [host01] ***************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [host01]

TASK: [ensure latest sysstat is installed] ************************************ 
changed: [host01]

PLAY RECAP ******************************************************************** 
host01                     : ok=2    changed=1    unreachable=0    failed=0
scrapbook@148696c2f85b:~/tutorial$ ansible-playbook -i myhosts site.yml

PLAY [host01] ***************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [host01]

TASK: [ensure latest sysstat is installed] ************************************ 
ok: [host01]

PLAY RECAP ******************************************************************** 
host01                     : ok=2    changed=0    unreachable=0    failed=0
scrapbook@148696c2f85b:~/tutorial$ sed -i -e 's/state: latest/state: absent/' -e 's/ensure.*/ensure sysstat is removed/' site.yml
scrapbook@148696c2f85b:~/tutorial$ cat site.yml 
---
- hosts: host01
  become: true
  tasks:
  - name: ensure sysstat is removed
    apt:
      name: sysstat
      state: absent
scrapbook@148696c2f85b:~/tutorial$ ansible-playbook -i myhosts site.yml

PLAY [host01] ***************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [host01]

TASK: [ensure sysstat is removed] ********************************************* 
changed: [host01]

PLAY RECAP ******************************************************************** 
host01                     : ok=2    changed=1    unreachable=0    failed=0

같이 보기

참고