- 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
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
本文介绍如何使用Ansible在OpenStack环境中自动部署多个Ubuntu实例,并配置基础应用。具体步骤包括定义主机变量、启动实例、等待SSH服务可用及安装必要的软件包。
2555

被折叠的 条评论
为什么被折叠?



