instance levantada

This commit is contained in:
RDF 2022-07-28 20:52:07 -03:00
parent 1d0e5df155
commit 35ad6d218c
23 changed files with 143 additions and 272 deletions

View File

@ -0,0 +1,34 @@
# ansible-playbook Playbooks/01-A-OPENLDAP.yml -i Inventories/QA -v -t 'deploy' --ask-become-pass
# ansible-playbook Playbooks/01-A-OPENLDAP.yml -i Inventories/QA -v -t 'deploy' --become-password-file
- hosts: ubuntu_lxd
gather_facts: false
tags: deploy
vars:
DIR: "~/OpenLDAP/"
tasks:
- name: Create a directory if it does not exist
ansible.builtin.file:
path: "{{DIR}}"
state: directory
mode: '0755'
- ansible.builtin.copy:
src: files/OpenLDAP.tf
dest: "{{DIR}}"
# Instalar terraform desde ansible con apt
# usar el socket sin sudo
# storage pool zfs
#- become: true
# ansible.builtin.shell: |
# apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
# apt install terraform
- become: true
community.general.terraform:
project_path: '/home/renzo/OpenLDAP'
force_init: true
state: present

View File

@ -1,22 +1,33 @@
# ansible-playbook Playbooks/01-UBUNTU-LXD.yml -i Inventories/QA --ask-become-pass
# ansible-playbook Playbooks/01-UBUNTU-LXD.yml -i Inventories/QA -v -t 'deploy' --become-password-file .sudo_pass
- hosts: ubuntu_lxd
vars:
sudoers:
- lxd
gather_facts: true
gather_facts: false
tags:
- deploy
become: true
tasks:
#- ansible.builtin.include_role: name=new_sudoers_user
- name: Install packages
ansible.builtin.package:
name: "{{item}}"
state: present
with_items:
- "ansible"
- "zfsutils-linux"
- name: Update, Upgrade & Install dependencies
become: true
block:
- apt: update_cache=yes upgrade=full
- ansible.builtin.package: name="{{item}}" state=present
with_items:
- ansible
- zfsutils-linux
- python3-pip
- lxc
- build-essential
- autoconf
- libtool
- pkg-config
- idle-python2.7
- libgle3
- terraform
- ansible.builtin.include_role: name=init_lxd
- pip: name=pylxd
- script: Playbooks/files/OpenLDAP.py
- ansible.builtin.include_role:
name: init_lxd
#vars:
# - lxd_init_template_config_path="/path/to/my/custom/template"
@ -24,14 +35,13 @@
- hosts: ubuntu_lxd
tags:
- rollback
tasks:
become: true
tasks:
- shell: "snap remove --purge lxd"
become: true
- name: Install packages
ansible.builtin.package:
name: "{{item}}"
state: absent
- pip: name=lxc-python2 state=absent
- ansible.builtin.package: name="{{item}}" state=absent
with_items:
- "ansible"
- "zfsutils-linux"
- "python3-pip"
- "lxc"

View File

@ -0,0 +1,25 @@
from pylxd import Client
# Project
lxd_proj = "MPS-LDAP"
lxd_proj_desc = "Proyecto para OpenLDAP & su cliente PHP LDAP Admin"
lxd_proj_config = {'limits.instances': '2'}
f = False
for project in Client().projects.all():
if project.name == lxd_proj:
f = True
break
if not f:
project = Client().projects.create(
lxd_proj, description=lxd_proj_desc, config=lxd_proj_config)
LXD = Client(project=lxd_client)
# Create Network if not exists
# Create Storage Pool if not exists
# Create instance if not exists
ldap_instance = "OpenLDAP"

View File

@ -0,0 +1,30 @@
terraform {
required_providers {
lxd = {
source = "terraform-lxd/lxd"
}
}
}
provider "lxd" {
generate_client_certificates = true
accept_remote_certificate = true
}
resource "lxd_cached_image" "focal" {
source_remote = "ubuntu"
source_image = "focal/amd64"
}
resource "lxd_container" "test1" {
name = "test1"
image = lxd_cached_image.focal.fingerprint
ephemeral = false
config = {
"boot.autostart" = true
}
limits = {
cpu = 2
}
}

View File

@ -1,38 +0,0 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@ -11,4 +11,4 @@ storage_pool_name: "default"
storage_pool_driver: "zfs"
storage_pool_size: "20GB"
# - Network
network_default_name: "lxdbr0"
network_default_name: "bridge1"

View File

@ -1,2 +0,0 @@
---
# handlers file for roles/init_lxd

View File

@ -1,52 +0,0 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@ -7,14 +7,14 @@
classic: yes
- ansible.builtin.debug:
var: hostvars[inventory_hostname]['ansible_default_ipv6']['address']
var: hostvars[inventory_hostname]['ansible_default_ipv4']['address']
verbosity: 1
- delegate_to: localhost
delegate_facts: true
ansible.builtin.copy:
content: "{{hostvars[inventory_hostname]}}"
dest: ./test.json
#- delegate_to: localhost
# delegate_facts: true
# ansible.builtin.copy:
# content: "{{hostvars[inventory_hostname]}}"
# dest: ./test.json
- delegate_to: localhost
delegate_facts: true

View File

@ -7,16 +7,16 @@ networks:
- name: {{network_default_name}}
project: {{lxd_project_name}}
type: bridge
config:
#config:
# IPv4
ipv4.nat: "true"
ipv4.address: {{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}
# ipv4.nat: "true"
# ipv4.address: {{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}
# IPv6
ipv6.nat: "true"
# ipv6.nat: "true"
# --
storage_pools:
- name: {{storage_pool}}
- name: {{storage_pool_name}}
driver: {{storage_pool_driver}}
config:
size: {{storage_pool_size}}
@ -32,14 +32,14 @@ profiles:
type: nic
root:
path: /
pool: {{storage_pool}}
pool: {{storage_pool_name}}
type: disk
# --
projects:
- config:
- name: {{lxd_project_name}}
config:
features.images: "true"
features.networks: "true"
features.profiles: "true"
features.storage.volumes: "true"
name: {{lxd_project_name}}
features.storage.volumes: "true"

View File

@ -1,2 +0,0 @@
localhost

View File

@ -1,5 +0,0 @@
---
- hosts: localhost
remote_user: root
roles:
- roles/init_lxd

View File

@ -1,3 +0,0 @@
---
# vars file for roles/init_lxd
lxd_init_yaml_config_path: "files/default_config.yml"

View File

@ -1,29 +0,0 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -1,38 +0,0 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@ -1,2 +0,0 @@
---
# handlers file for roles/new_sudoers_user

View File

@ -1,52 +0,0 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@ -1,2 +0,0 @@
localhost

View File

@ -1,5 +0,0 @@
---
- hosts: localhost
remote_user: root
roles:
- roles/new_sudoers_user

View File

@ -1,2 +0,0 @@
---
# vars file for roles/new_sudoers_user

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,9 @@
### Probablemente precises generar tu propio ansible.cfg y configurarlo.
# Run 01
ansible-playbook Playbooks/01-UBUNTU-LXD.yml -i Inventories/QA -v
ansible-playbook Playbooks/01-UBUNTU-LXD.yml -i Inventories/QA -v [-t 'rollback']
### Rollback
añadir el tag 'rollback'
[-t 'rollback']