본문 바로가기

리눅스

[Ansible] ansible-playbook apache(httpd) install

반응형

ansible-playbook apache(httpd) install

os-pkg-apache.yaml edit

vim os-pkg-apache.yaml
---
### ansible -i ~/ansible-spec/inventory kube-node1 -m gather_facts
### ansible-doc yum
### ansible-doc apt
- hosts: all
  gather_facts: yes

  tasks:
    - name: install apache on centos
      yum: 
        name: httpd
        state: present
      when: ansible_facts['distribution'] == "CentOS" and ansible_facts['lsb']['major_release'] | int >= 6
      register: centos2output
    - debug: var=centos2output.stdout
  
    - name: install apache on ubuntu
      apt: 
        name: apache2
        state: present
        update_cache: yes
      when: ansible_facts['distribution'] == "Ubuntu" and ansible_facts['lsb']['major_release'] | int >= 18
      register: ubuntu2output
    - debug: var=ubuntu2output.stdout

ansible-playbook 실행

ansible-playbook -i ./inventory --limit kube-node1 os-pkg-apache.yaml -T 300 --become
$ ansible-playbook -i ./inventory --limit kube-node1 os-pkg-apache.yaml -T 300 --become

PLAY [all] ******************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************
ok: [kube-node1]

TASK [install apache on centos] *********************************************************************************
skipping: [kube-node1]

TASK [debug] ****************************************************************************************************
ok: [kube-node1] => {
    "centos2output.stdout": "VARIABLE IS NOT DEFINED!"
}

TASK [install apache on ubuntu] **********************************************************************************
changed: [kube-node1]

TASK [debug] *****************************************************************************************************
ok: [kube-node1] => {
    "ubuntu2output.stdout": "Reading package lists...\n
   ...
   NEEDRESTART-SVC: unattended-upgrades.service\n"
}

PLAY RECAP *******************************************************************************************************
kube-node1                 : ok=4    changed=1    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

 

참고URL

- ansible-playbook : https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html

- Playbook Keywords : https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html

- [Ansible] 앤서블 플레이북 키워드(Playbook Keywords) : https://anti1346.tistory.com/1380

 

728x90
반응형