Skip to content

Instantly share code, notes, and snippets.

@ualmtorres
Last active December 14, 2018 05:23
Show Gist options
  • Save ualmtorres/48282e19fcda125fc3205562066c58dc to your computer and use it in GitHub Desktop.
Save ualmtorres/48282e19fcda125fc3205562066c58dc to your computer and use it in GitHub Desktop.
Setup a new OpenStack Project with a new user, network and watchers
# Inventory hosts.cfg file
[controller]
10.0.0.2
- hosts: all
become: true
roles:
- setup-new-project
- name: Include var file
include_vars:
file: users.yml
- name: Create a project
os_project:
cloud=lowcost
state=present
name={{ item.project }}
description="Proyecto de {{ item.user }}"
enabled=True
domain=default
with_items:
- "{{ projects }}"
- name: Grant admin role on user admin in the project
os_user_role:
cloud=lowcost
user=admin
role=admin
project={{ item.project }}
with_items:
- "{{ projects }}"
- name: Create the user for the project
os_user:
cloud=lowcost
state=present
name={{ item.project }}
password={{ item.password }}
description={{ item.user }}
update_password=on_create
email={{ item.email }}
default_project={{ item.project }}
domain=default
with_items:
- "{{ projects }}"
- name: Grant user role on user in the project
os_user_role:
cloud=lowcost
user={{ item.project }}
role=user
project={{ item.project }}
with_items:
- "{{ projects }}"
- name: Grant watchers to the projects
os_user_role:
cloud: lowcost
project: "{{ item[0].project }}"
user: "{{ item[1].username }}"
role: "{{ item[1].role }}"
with_nested:
- "{{ projects }}"
- "{{ watchers }}"
ignore_errors: True
- name: Create the network of the project
os_network:
cloud=lowcost
state=present
name="{{ item.project }}-net"
project={{ item.project }}
with_items:
- "{{ projects }}"
- name: Create the subnet
os_subnet:
cloud=lowcost
state=present
network_name="{{ item.project }}-net"
name="{{ item.project }}-subnet"
cidr={{ cidr }}
dns_nameservers={{ dns }}
project={{ item.project }}
with_items:
- "{{ projects }}"
- name: Create the router connecting the network and the subnet
os_router:
cloud=lowcost
state=present
name="{{ item.project }}-router"
network={{ network }}
interfaces="{{ item.project }}-subnet"
project={{ item.project }}
with_items:
- "{{ projects }}"
- name: Apply quotas
os_quota:
cloud: lowcost
name: "{{ item.project }}"
instances: " {{ quota.instances}} "
cores: " {{ quota.cores}} "
ram: " {{ quota.ram }} "
gigabytes: " {{ quota.gigabytes }} "
backups: " {{ quota.backups }} "
backup_gigabytes: " {{ quota.backup_gigabytes }} "
floatingip: " {{ quota.floatingip }} "
gigabytes_types:
gigabytes_lvm: " {{ quota.gigabytes_lvm }} "
snapshots: " {{ quota.snapshots }} "
snapshots_types:
snapshots_lvm: " {{ quota.snapshots_lvm }} "
volumes: " {{ quota.volumes}} "
volumes_types:
volumes_lvm: " {{ quota.volumes_lvm }} "
with_items:
- "{{ projects }}"
when: item.quota == "present"
network: "ext-net"
cidr: 30.0.0.0/24
dns:
- 150.214.156.2
- 8.8.8.8
#Para la cuota predetermianda, poner state a absent
quota: {
state: present,
instances: 10,
cores: 20,
ram: 324800,
gigabytes: 60,
backups: 0,
backup_gigabytes: 0,
floatingip: 10,
gigabytes_lvm: 60,
snapshots: 0,
snapshots_lvm: 0,
volumes: 2,
volumes_lvm: 2
}
watchers:
- {username: "teacher1", role: "admin"}
- {username: "teacher2", role: "admin"}
projects:
- {project: "john.doe", user: "John Doe", email: "john.done@gmail.com", password: "xxx", quota: "absent"}
- {project: "mary.smith", user: "Mary Smith", email: "mary.smith@gmail.com", password: "xxx", quota: "present"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment