The playbook to creeate the VMs from openstack cluster

本文介绍如何使用Ansible在OpenStack环境中自动部署多个Ubuntu实例,并配置基础应用。具体步骤包括定义主机变量、启动实例、等待SSH服务可用及安装必要的软件包。
- name: Deploy new instances in OpenStack
  hosts: localhost
  connection: local
  gather_facts: False
  user: ubuntu
 
  vars:
    name: cache-01
    image: ubuntu-14.04
    network: example-net
    key_name: example-key
    flavor: c1.c1r1
    security_groups: example-sg
    count: 2

  tasks:
    - name: Launch the instances
      os_server:
        name: "{{ name }}"
        flavor: "{{ flavor }}"
        image: "{{ image }}"
        key_name: "{{ key_name }}"
        state: present
        wait: true
        network: "{{ network }}"
        security_groups: "{{ security_groups }}"
        auto_ip: true
      register: newnodes
      with_sequence:
        count={{ count }}
        

    - add_host: name={{ item.server.public_v4 }}
                groups=created_nodes
                ansible_user=ubuntu
                instance_name={{ item.server.name }}
      with_items: "{{ newnodes.results }}"



- name: Configure nodes
  hosts: created_nodes
  become: yes
  become_method: sudo
  gather_facts: false
  tasks:
    - name: "Wait for SSH "
      local_action: wait_for port=22 host="{{ inventory_hostname }}" search_regex=OpenSSH delay=5
      become: False

    - name: install apps
      apt: name={{ item }} update_cache=yes state=latest
      with_items:
        - nrpe
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值