MACOS 에서 vagrant와 virtualbox를 설치한다. 

http://knight76.tistory.com/entry/MAC-OS%EC%97%90%EC%84%9C-virtualbox-vagrant-%EC%84%A4%EC%B9%98




1. 설치 

아래 주소에서 ansible을 설치한다. 

http://docs.ansible.com/intro_installation.html


brew를 이용한다. 

$ brew update

$ brew install ansible


또는 pip를 이용한다. 


$ sudo easy_install pip

$ sudo pip install ansible


pip설치 중 문제(OS X Mavericks)가 나면 아래 내용을 참고 한다.  

http://knight76.tistory.com/entry/clang-error-unknown-argument-mnofusedmadd





2.  Vagrant 파일 수정


precise64를 사용하는 것으로 수정하고 playbook.yml 파일을 가지고 배포하도록 한다. 


# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!

VAGRANTFILE_API_VERSION = "2"


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    config.vm.box = "precise64"

    config.vm.box_url = "http://files.vagrantup.com/precise64.box"


    #config.vm.network :public_network

    config.vm.hostname = "web"


    config.vm.provision "ansible" do |ansible|

        ansible.playbook = "playbook.yml"

    end

end



yml에 대해서 궁금하면 아래 링크를 참조한다. 

http://knight76.tistory.com/entry/yaml-yml-%EC%9E%90%EB%A3%8C-%EA%B3%B5%EC%9C%A0





3. playbook.yml 추가


가상서버에 ssh 로 접근해서 ls -al /home 명령어를 실행하고 결과값을 출력하라는 내용이다. 


- hosts: all

  user: vagrant

  sudo: yes

  tasks:

  - name: test

    action:  command ls -al /home

    register: vagrant

  - debug: var=vagrant.stdout_lines





4. 테스트


$ vagrant provision

==> default: Running provisioner: ansible...


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


GATHERING FACTS *************************************************************** 

ok: [default]


TASK: [test] ****************************************************************** 

changed: [default]


TASK: [debug var=vagrant.stdout_lines] **************************************** 

ok: [default] => {

    "vagrant.stdout_lines": [

        "total 12", 

        "drwxr-xr-x  3 root    root    4096 Sep 14  2012 .", 

        "drwxr-xr-x 24 root    root    4096 Jun 13 01:32 ..", 

        "drwxr-xr-x  5 vagrant vagrant 4096 Jun 13 01:32 vagrant"

    ]

}


PLAY RECAP ******************************************************************** 

default                    : ok=3    changed=1    unreachable=0    failed=0   



아래와 같이 나오면 제대로 동작했다는 의미이다.



* 이슈

vagrant-ansible을 사용할 때 Centos 일부 계열은 고민할 필요학 있다. 따라서 처음 사용자는 될 수 있으면 centos 보다는 ubunut 계열을 사용하는 것이 좋은 듯 하다. 


예를 들어 vagrant 이미지를 centos  이미지로 설치했다고 가정하자. vagrant up 명령시 ssh connection timeout이 발생된다. 



$ vagrant up 시 에러..

    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
^C==> default: Waiting for cleanup before exiting...
^C==> default: Exiting immediately, without cleanup!


그리고, playbook을 실행하면 에러가 발생한다. 


$ ansible-playbook -i hosts setup.xml

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

GATHERING FACTS ***************************************************************
failed: [192.168.1.50] => {"failed": true, "parsed": false}
invalid output was: SUDO-SUCCESS-sragynknplstvlayqgkszdzjtvbzwjuj
Error: ansible requires a json module, none found!

TASK: [debug msg="the value of foo.txt is "] **********************************
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ********************************************************************
           to retry, use: --limit @/Users/knight/setup.xml.retry

192.168.1.50               : ok=0    changed=0    unreachable=0    failed=1  






명확하게 어떤 에러가 나는지 보려면 ansible 명령어를 이용해보면 더 잘 알 수 있다.. 


$ ansible all -i hosts -m ping

192.168.1.50 | FAILED >> {
    "failed": true,
    "msg": "Error: ansible requires a json module, none found!",
    "parsed": false
}



즉, CentOS 에 python-simplejson 쪽 이슈가 있다.. python-simplejson을 설치해야 한다....



Managed Node Requirements

On the managed nodes, you only need Python 2.4 or later, but if you are running less than Python 2.5 on the remotes, you will also need:

  • python-simplejson



그래서, ansible 예제로 많이 쓰이는 ubuntu (lucid, precise)를 추천한다. 

또한 yum 설치방식보다는 apt-get을 이용한 설치 방식이 귀찮은 일을 최대한 적게 해주는 듯 했다. 

Posted by '김용환'
,