summaryrefslogtreecommitdiff
path: root/playbooks
diff options
context:
space:
mode:
authorjerome <jerome@xlinfo.fr>2025-02-07 11:40:40 +0100
committerjerome <jerome@xlinfo.fr>2025-02-07 11:40:40 +0100
commit69b3a2cf08873de59883e3c2661ea1b57726eee3 (patch)
tree79824f61bf1a6b556d85fd652f3b6ead787a4744 /playbooks
downloadterraform-ansible-69b3a2cf08873de59883e3c2661ea1b57726eee3.tar.gz
terraform-ansible-69b3a2cf08873de59883e3c2661ea1b57726eee3.zip
premier commit
Diffstat (limited to 'playbooks')
-rw-r--r--playbooks/files/default.conf8
-rw-r--r--playbooks/hosts2
-rw-r--r--playbooks/lamp.yml3
-rw-r--r--playbooks/lamp/.travis.yml29
-rw-r--r--playbooks/lamp/README.md38
-rw-r--r--playbooks/lamp/defaults/main.yml2
-rw-r--r--playbooks/lamp/handlers/main.yml7
-rw-r--r--playbooks/lamp/meta/main.yml53
-rw-r--r--playbooks/lamp/tasks/Debian-phpmyadmin.yml23
-rw-r--r--playbooks/lamp/tasks/RedHat-phpmyadmin.yml23
-rw-r--r--playbooks/lamp/tasks/clean.yml15
-rw-r--r--playbooks/lamp/tasks/main.yml57
-rw-r--r--playbooks/lamp/tasks/test.yml19
-rw-r--r--playbooks/lamp/templates/index.j220
-rw-r--r--playbooks/lamp/tests/inventory2
-rw-r--r--playbooks/lamp/tests/test.yml5
-rw-r--r--playbooks/lamp/vars/Debian.yml14
-rw-r--r--playbooks/lamp/vars/RedHat.yml14
-rw-r--r--playbooks/lamp/vars/main.yml2
-rw-r--r--playbooks/lxc.yml62
20 files changed, 398 insertions, 0 deletions
diff --git a/playbooks/files/default.conf b/playbooks/files/default.conf
new file mode 100644
index 0000000..bc5449b
--- /dev/null
+++ b/playbooks/files/default.conf
@@ -0,0 +1,8 @@
+lxc.net.0.type = veth
+lxc.net.0.link = lxcbr0
+lxc.net.0.flags = up
+lxc.net.0.hwaddr = xx:xx:xx:xx:xx:xx
+
+lxc.apparmor.profile = generated
+lxc.apparmor.allow_nesting = 1
+lxc.start.auto = 1
diff --git a/playbooks/hosts b/playbooks/hosts
new file mode 100644
index 0000000..c476980
--- /dev/null
+++ b/playbooks/hosts
@@ -0,0 +1,2 @@
+10.0.3.153
+10.0.3.68 \ No newline at end of file
diff --git a/playbooks/lamp.yml b/playbooks/lamp.yml
new file mode 100644
index 0000000..bbfb572
--- /dev/null
+++ b/playbooks/lamp.yml
@@ -0,0 +1,3 @@
+- hosts: all
+ roles:
+ - lamp
diff --git a/playbooks/lamp/.travis.yml b/playbooks/lamp/.travis.yml
new file mode 100644
index 0000000..36bbf62
--- /dev/null
+++ b/playbooks/lamp/.travis.yml
@@ -0,0 +1,29 @@
+---
+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/ \ No newline at end of file
diff --git a/playbooks/lamp/README.md b/playbooks/lamp/README.md
new file mode 100644
index 0000000..225dd44
--- /dev/null
+++ b/playbooks/lamp/README.md
@@ -0,0 +1,38 @@
+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).
diff --git a/playbooks/lamp/defaults/main.yml b/playbooks/lamp/defaults/main.yml
new file mode 100644
index 0000000..56675e7
--- /dev/null
+++ b/playbooks/lamp/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+# vars file for lamp
diff --git a/playbooks/lamp/handlers/main.yml b/playbooks/lamp/handlers/main.yml
new file mode 100644
index 0000000..b583d01
--- /dev/null
+++ b/playbooks/lamp/handlers/main.yml
@@ -0,0 +1,7 @@
+---
+# handlers file for lamp
+- name: restarting_apache
+ service:
+ name: '{{apache.service}}'
+ state: restarted
+
diff --git a/playbooks/lamp/meta/main.yml b/playbooks/lamp/meta/main.yml
new file mode 100644
index 0000000..227ad9c
--- /dev/null
+++ b/playbooks/lamp/meta/main.yml
@@ -0,0 +1,53 @@
+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.9
+
+ # 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.
+ \ No newline at end of file
diff --git a/playbooks/lamp/tasks/Debian-phpmyadmin.yml b/playbooks/lamp/tasks/Debian-phpmyadmin.yml
new file mode 100644
index 0000000..8bfb478
--- /dev/null
+++ b/playbooks/lamp/tasks/Debian-phpmyadmin.yml
@@ -0,0 +1,23 @@
+---
+- name: configuration debconf
+ block:
+ - debconf:
+ name: phpmyadmin
+ question: 'phpmyadmin/reconfigure-webserver'
+ value: 'apache2'
+ vtype: select
+ - debconf:
+ name: phpmyadmin
+ question: 'phpmyadmin/mysql/admin-pass'
+ value: '(password omitted)'
+ vtype: string
+ - debconf:
+ name: phpmyadmin
+ question: 'phpmyadmin/dbconfig-install'
+ value : 'true'
+ vtype: boolean
+
+- name: installation phpmyadmin
+ package:
+ name: phpmyadmin
+ state: present
diff --git a/playbooks/lamp/tasks/RedHat-phpmyadmin.yml b/playbooks/lamp/tasks/RedHat-phpmyadmin.yml
new file mode 100644
index 0000000..569ddd2
--- /dev/null
+++ b/playbooks/lamp/tasks/RedHat-phpmyadmin.yml
@@ -0,0 +1,23 @@
+---
+- name: installation epel-release
+ package:
+ name: epel-release
+ state: present
+
+- name: installation phpmyadmin
+ package:
+ name: phpmyadmin
+ state: present
+
+- name: phpmyadmin.conf
+ replace:
+ path: /etc/httpd/conf.d/phpMyAdmin.conf
+ regexp: "Require local"
+ replace: "Require all granted"
+ after: "<Directory /usr/share/phpMyAdmin/>"
+ before: "</Directory>"
+ notify: restarting_apache
+
+- name: database
+ shell: mysql < /usr/share/phpMyAdmin/sql/create_tables.sql
+
diff --git a/playbooks/lamp/tasks/clean.yml b/playbooks/lamp/tasks/clean.yml
new file mode 100644
index 0000000..7e3571e
--- /dev/null
+++ b/playbooks/lamp/tasks/clean.yml
@@ -0,0 +1,15 @@
+---
+- name: supprimer la base de données test
+ community.mysql.mysql_db:
+ name: toto
+ state: absent
+ login_unix_socket: '{{mariadb.socket}}'
+
+- name: supprimer l'utilisateur test
+ community.mysql.mysql_user:
+ name: toto
+ password: secret
+ priv: 'toto.*:ALL'
+ state: absent
+ login_unix_socket: '{{mariadb.socket}}'
+
diff --git a/playbooks/lamp/tasks/main.yml b/playbooks/lamp/tasks/main.yml
new file mode 100644
index 0000000..17cf4d8
--- /dev/null
+++ b/playbooks/lamp/tasks/main.yml
@@ -0,0 +1,57 @@
+---
+# tasks file for lamp
+- include_vars: '{{ansible_os_family}}.yml'
+ tags:
+ - test
+ - clean
+
+- name: installation de lamp
+ package:
+ update_cache: true
+ name: "{{item}}"
+ state: present
+ with_items: '{{lamp_packages}}'
+
+- name: activation des services sur Redhat
+ service:
+ state: started
+ name: '{{item}}'
+ with_items:
+ - httpd
+ - mariadb
+ when: ansible_os_family == 'RedHat'
+
+- name : activation du mod_rewrite d'apache sur Debian
+ apache2_module:
+ state: present
+ name: rewrite
+ when: ansible_os_family == 'Debian'
+ notify:
+ - restarting_apache
+
+- name: mise en place de index.html
+ template:
+ src: templates/index.j2
+ dest: /var/www/html/index.html
+ owner: "{{apache.user}}"
+ group: "{{apache.user}}"
+ mode: 0644
+
+- name: installation de phpmyadmin
+ include_tasks: '{{ansible_os_family}}-phpmyadmin.yml'
+ vars:
+ - apache: '{{apache}}'
+ tags: phpmyadmin
+
+- name: test user
+ import_tasks: test.yml
+ tags:
+ - never
+ - test
+
+- name: clean user
+ import_tasks: clean.yml
+ tags:
+ - never
+ - clean
+
diff --git a/playbooks/lamp/tasks/test.yml b/playbooks/lamp/tasks/test.yml
new file mode 100644
index 0000000..c3d9c32
--- /dev/null
+++ b/playbooks/lamp/tasks/test.yml
@@ -0,0 +1,19 @@
+---
+- name: install dépendances python
+ package:
+ name: '{{ mariadb.pythonlib }}'
+ state: present
+
+- name: Créer la base de données test
+ community.mysql.mysql_db:
+ name: toto
+ state: present
+ login_unix_socket: '{{mariadb.socket}}'
+
+- name: Créer un utilisateur test
+ community.mysql.mysql_user:
+ name: toto
+ password: secret
+ priv: 'toto.*:ALL'
+ state: present
+ login_unix_socket: '{{mariadb.socket}}'
diff --git a/playbooks/lamp/templates/index.j2 b/playbooks/lamp/templates/index.j2
new file mode 100644
index 0000000..29619c2
--- /dev/null
+++ b/playbooks/lamp/templates/index.j2
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>{{ansible_distribution}} Apache Web Server</title>
+<meta charset="utf-8" />
+</head>
+<body>
+<h1>{{ansible_distribution}} Apache Web Server</h1>
+<h2>Site en Constuction</h2>
+{% if lamp_packages is defined %}
+<h3>Packages :</h3>
+<ul>
+{% for item in lamp_packages %}
+<li>{{item}}</li>
+{% endfor %}
+</ul>
+{% endif %}
+<p>Généré par {{ ansible_distribution }} {{ ansible_distribution_version }}</p>
+</body>
+</html>
diff --git a/playbooks/lamp/tests/inventory b/playbooks/lamp/tests/inventory
new file mode 100644
index 0000000..878877b
--- /dev/null
+++ b/playbooks/lamp/tests/inventory
@@ -0,0 +1,2 @@
+localhost
+
diff --git a/playbooks/lamp/tests/test.yml b/playbooks/lamp/tests/test.yml
new file mode 100644
index 0000000..10107f3
--- /dev/null
+++ b/playbooks/lamp/tests/test.yml
@@ -0,0 +1,5 @@
+---
+- hosts: localhost
+ remote_user: root
+ roles:
+ - lamp \ No newline at end of file
diff --git a/playbooks/lamp/vars/Debian.yml b/playbooks/lamp/vars/Debian.yml
new file mode 100644
index 0000000..1c7659f
--- /dev/null
+++ b/playbooks/lamp/vars/Debian.yml
@@ -0,0 +1,14 @@
+lamp_packages:
+ - apache2
+ - mariadb-server
+ - php
+ - php-mysql
+
+apache:
+ service: apache2
+ user: www-data
+
+mariadb:
+ socket: /var/run/mysqld/mysqld.sock
+ pythonlib: python3-pymysql
+
diff --git a/playbooks/lamp/vars/RedHat.yml b/playbooks/lamp/vars/RedHat.yml
new file mode 100644
index 0000000..b8033ee
--- /dev/null
+++ b/playbooks/lamp/vars/RedHat.yml
@@ -0,0 +1,14 @@
+lamp_packages:
+ - httpd
+ - mariadb-server
+ - php
+ - php-mysqlnd
+
+apache:
+ service: httpd
+ user: apache
+
+mariadb:
+ socket: /var/lib/mysql/mysql.sock
+ pythonlib: python3-PyMySQL
+
diff --git a/playbooks/lamp/vars/main.yml b/playbooks/lamp/vars/main.yml
new file mode 100644
index 0000000..56675e7
--- /dev/null
+++ b/playbooks/lamp/vars/main.yml
@@ -0,0 +1,2 @@
+---
+# vars file for lamp
diff --git a/playbooks/lxc.yml b/playbooks/lxc.yml
new file mode 100644
index 0000000..8c40007
--- /dev/null
+++ b/playbooks/lxc.yml
@@ -0,0 +1,62 @@
+---
+- hosts: all
+ tasks:
+ - name: install lxc
+ package:
+ name: '{{item}}'
+ state: present
+ update_cache: yes
+ with_items:
+ - lxc
+ - python3-lxc
+
+ - name: Configuration de lxc
+ copy:
+ src: default.conf
+ dest: /etc/lxc/default.conf
+
+ - name: Creation d'un container rocky
+ community.general.lxc_container:
+ name: rocky-lxc
+ template: download
+ template_options: --dist rockylinux --release 9 --arch amd64
+ state: started
+ container_command: |
+ sleep 5
+ dnf install -y openssh-server python3
+ systemctl enable --now sshd
+
+
+ - name: Creation d'un container debian
+ community.general.lxc_container:
+ name: debian-lxc
+ template: download
+ template_options: --dist debian --release bookworm --arch amd64
+ state: started
+ container_command: |
+ sleep 5
+ apt install -y openssh-server python3
+ systemctl enable --now ssh
+
+ - name: copie des clefs ssh
+ copy:
+ src: "~/.ssh/id_rsa.pub"
+ dest: "{{item}}"
+ mode: "0600"
+ with_items:
+ - /var/lib/lxc/debian-lxc/rootfs/root/.ssh/authorized_keys
+ - /var/lib/lxc/rocky-lxc/rootfs/root/.ssh/authorized_keys
+
+ - name: recuperation ip rocky
+ shell: "lxc-info -iH rocky-lxc"
+ register: ip_rocky
+
+ - name: recuperation ip debian
+ shell: "lxc-info -iH debian-lxc"
+ register: ip_debian
+
+ - name: inventaire
+ remote_user: "jerome"
+ become: no
+ local_action: copy content="{{ip_rocky.stdout}}\n{{ip_debian.stdout}}" dest="hosts"
+