티스토리 뷰

DevOps/System&Tools

ansible with openstack

Jacob_baek 2017. 7. 28. 14:46


VM 생성 및 삭제


playbook을 실행하는 machine에서의 playbook은 다음과 같이 구성한다.

host를 localhost로 하고 auth_url을 원격에 존재하는 keystone 주소를 입력한다.


즉 아래와 같은 구성이 된다.

test machine(laptop) 혹은 undercloud director => openstack keystone service


아래와 같은 package가 필요하다.

yum install python-pip python-heatclient python-openstackclient python2-shade

pip install virtualenvwrapper

- https://dzone.com/articles/full-stack-automation-with-ansible-andnbspopenstac-1


아래와 같이 playbook 실행시 에러가 발생될 수 있다.

TASK [deploy an instance] ******************************************************

fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "shade is required for this module"}

        to retry, use: --limit @/home/stack/playbooks/openstack_vm_deploy.retry


이와 같은 경우 pip install shade로 해당 모듈을 설치한다.

- https://github.com/CentOS-PaaS-SIG/linchpin/issues/71


sample code

- name : deploy vm on openstack

  hosts : localhost

  gather_facts: false

  tasks:

    - name: create network

      os_network:

        name: testnetwork

        state: present

        external: false

        project: TestProject

    - name: create subnet

      os_subnet:

        name: testsubnet

        state: present

        network_name: testnetwork

        cidr: 100.100.100.0/24

        dns_nameservers:

          - 8.8.8.8

    - name: create router

      os_router:

        state: present

        name: ExternalNetwork

        interfaces:

          - testsubnet

    - name: deploy an instance

      os_server:

        auth:

        state: present
        name: srvbyansible
        image: cirros
        timeout: 200
        flavor: m1.small
        auto_floating_ip: no
        network: testnetwork
        security_groups: default

해당 playbook을 실행하기전에 source .overcloudrc 를 수행하거나 혹은 아래 auth 항목을 각 task 밑에 추가해야한다.
        auth:
          auth_url: http://keystone_ip:5000/v2.0
          username: admin
          password: password
          project_name: TestProject

혹은 variables을 아래와 같이 상단에 추가하고 
  vars:
    os_auth:
      auth_url : http://keystone_ip:5000/v2.0
      username : admin
      password : password
      project_name: TestProject

각 task의 module 밑에 아래의 auth 항목을 추가하여 사용할 수 있다.
      auth: "{{ os_auth }}"

os_project, os_user 등의 경우 clouds.yml을 추가로 생성하여 한번에 auth를 처리할 수 있다.


load balancer에 관련된 module은 아직 core에 반영되지는 않았다. 


아래는 core는 아니지만 octavia를 사용할 수 있는 모듈에 대한 소개이다.

- https://docs.openstack.org/openstack-ansible-os_octavia/latest/


참고로 아래 링크로 이동해보면 os_(openstack)로 시작하는 ansible module을 확인할 수 있다.

- https://github.com/openstack?utf8=%E2%9C%93&q=os%5C_&type=&language=


아래 링크에 sample code를 참고하여 project 생성부터 member 등록까지 완료할수 있다.

(아래 ansible은 uri module을 사용하여 인증토큰을 발급받고 project 및 user를 생성하고 role을 부여하는 yaml 파일이다.)

- https://github.com/vvaldez/ansible-openstack-api/blob/master/openstack-project-create.yml


아래 링크는 ansible 로 project 생성 부터 loadbalancer 생성까지 전체적인 flow를 ansible로 배포하는 yaml 파일이다.

https://github.com/jacobbaek/ansible-project/blob/master/openstack_vm_deploy.yml


참고사이트

http://superuser.openstack.org/articles/using-ansible-2-0-to-launch-a-server-on-openstack/

http://docs.ansible.com/ansible/latest/os_server_module.html

- https://www.snip2code.com/Snippet/1281428/Example-of-an-Ansible-playbook-that-inte


OpenStack 배포

To be continued

'DevOps > System&Tools' 카테고리의 다른 글

nexus  (0) 2019.11.12
k3s integrated with GitLab  (0) 2019.10.03
dynamic inventory  (0) 2018.07.24
ansible cisco  (0) 2017.09.28
ansible with vmware  (0) 2017.07.28
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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 29 30
글 보관함