commit a3ce91dc9dbff58dcc7428fd9dd0a2dd26335dc9 Author: Alex Date: Wed Nov 8 14:58:46 2023 +0000 first commit diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..88fc9d1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "ansible.python.interpreterPath": "/bin/python3.11" +} \ No newline at end of file diff --git a/1-1.practice-k8s.cloud.html b/1-1.practice-k8s.cloud.html new file mode 100644 index 0000000..0a60894 --- /dev/null +++ b/1-1.practice-k8s.cloud.html @@ -0,0 +1,12 @@ + + + Machine 1-1.practice-k8s.cloud + + +

Cette machine s’appelle 1-1.practice-k8s.cloud

+

Ci-dessous la liste de ces adresses :

+ + + \ No newline at end of file diff --git a/1-2.practice-k8s.cloud.html b/1-2.practice-k8s.cloud.html new file mode 100644 index 0000000..772a3c5 --- /dev/null +++ b/1-2.practice-k8s.cloud.html @@ -0,0 +1,12 @@ + + + Machine 1-2.practice-k8s.cloud + + +

Cette machine s’appelle 1-2.practice-k8s.cloud

+

Ci-dessous la liste de ces adresses :

+ + + \ No newline at end of file diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..b17205e --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,23 @@ +# Since Ansible 2.12 (core): +# To generate an example config file (a "disabled" one with all default settings, commented out): +# $ ansible-config init --disabled > ansible.cfg +# +# Also you can now have a more complete file by including existing plugins: +# ansible-config init --disabled -t all > ansible.cfg + +# For previous versions of Ansible you can check for examples in the 'stable' branches of each version +# Note that this file was always incomplete and lagging changes to configuration settings + +# for example, for 2.9: https://github.com/ansible/ansible/blob/stable-2.9/examples/ansible.cfg + +[defaults] +inventory = inventory.ini +remote_user = user-ansible +host_key_checking = false +vault_password_file = /root/ansible/vault.key + +[privilege_escalation] +become = True +become_method = sudo +become_user = root +become_ask_pass = False diff --git a/apache-inventaire.conf.tag.yml b/apache-inventaire.conf.tag.yml new file mode 100644 index 0000000..03509c3 --- /dev/null +++ b/apache-inventaire.conf.tag.yml @@ -0,0 +1,20 @@ +--- +- name: "Apache installation" + hosts: 1-1.practice-k8s.cloud + tasks: + - name: "Apache package installation" + yum: + name: "httpd" + state: "present" + - name: "Apache configuration" + template: + src: "inventory.conf.j2" + dest: "/etc/httpd/conf.d/inventory.conf" + owner: "apache" + group: "apache" + - name: "Start apache service" + tags: restart + service: + name: "httpd" + state: "started" + enabled: yes diff --git a/apache-inventaire.conf.yml b/apache-inventaire.conf.yml new file mode 100644 index 0000000..6bc8aa3 --- /dev/null +++ b/apache-inventaire.conf.yml @@ -0,0 +1,19 @@ +--- +- name: "Apache installation" + hosts: 1-1.practice-k8s.cloud + tasks: + - name: "Apache package installation" + yum: + name: "httpd" + state: "present" + - name: "Apache configuration" + template: + src: "inventory.conf.j2" + dest: "/etc/httpd/conf.d/inventory.conf" + owner: "apache" + group: "apache" + - name: "Start apache service" + service: + name: "httpd" + state: "started" + enabled: yes \ No newline at end of file diff --git a/apache-when-handler.yml b/apache-when-handler.yml new file mode 100644 index 0000000..1d7f306 --- /dev/null +++ b/apache-when-handler.yml @@ -0,0 +1,22 @@ +--- +- name: "Apache installation" + hosts: 1-1.practice-k8s.cloud + force_handlers: yes + tasks: + - name: "Apache configuration" + template: + src: "inventory.conf.j2" + dest: "/etc/httpd/conf.d/inventory.conf" + owner: "apache" + group: "apache" + notify: [ "Restart apache service" ] + - name: copy nothing - intended to fail + copy: + src: /tmp/nothing + dest: /var/www/html/nothing.html + + handlers: + - name: "Restart apache service" + service: + name: "httpd" + state: "restarted" diff --git a/apache-when.yml b/apache-when.yml new file mode 100644 index 0000000..d4a2961 --- /dev/null +++ b/apache-when.yml @@ -0,0 +1,23 @@ +--- +- name: "Apache installation" + hosts: 1-1.practice-k8s.cloud + tasks: + - name: "Apache package installation" + yum: + name: "httpd" + state: "present" + - name: "Apache configuration" + template: + src: "inventory.conf.j2" + dest: "/etc/httpd/conf.d/inventory.conf" + owner: "apache" + group: "apache" + register: apache_conf + - debug: var=apache_conf + - name: "Start apache service" + when: apache_conf.changed + tags: restart + service: + name: "httpd" + state: "started" + enabled: yes diff --git a/command-output-test.yml b/command-output-test.yml new file mode 100644 index 0000000..f2b9390 --- /dev/null +++ b/command-output-test.yml @@ -0,0 +1,18 @@ +--- +- name: test command output + hosts: all + tasks: + - name: Test for VG existance + command: vgs + register: vgout + ignore_errors: True + + - name: Show variable value + debug: + var: vgout + + - name: print + debug: + msg: vg does not exist + when: "'No such' in vgout.msg" + diff --git a/fichier-variables.yml b/fichier-variables.yml new file mode 100644 index 0000000..04e87f8 --- /dev/null +++ b/fichier-variables.yml @@ -0,0 +1 @@ +varfile: file \ No newline at end of file diff --git a/filter-1.yml b/filter-1.yml new file mode 100644 index 0000000..4cf83e8 --- /dev/null +++ b/filter-1.yml @@ -0,0 +1,18 @@ +--- +- hosts: localhost + vars_prompt: + - name: filesize + prompt: "specify a file size in megabytes" + private: no + tasks: + - name: check if file size is valid + assert: + that: + - "{{ (filesize | int) <= 100 }}" + - "{{ (filesize | int) >= 1 }}" + fail_msg: "file size must be between 0 and 100" + success_msg: "file size is good, let's continue" + - name: debug + debug: + msg: "filesize : {{ filesize }}" + diff --git a/iden-creat-user.yaml b/iden-creat-user.yaml new file mode 100644 index 0000000..a36ac9d --- /dev/null +++ b/iden-creat-user.yaml @@ -0,0 +1,20 @@ +--- +- name: create user {{ user }} + hosts: 1-1.practice-k8s.cloud + vars: + user: user_paul + tasks: + - name: check-user + command: id {{ user }} + register: iduser + - name: + debug: + var: iduser + - name: before-check + fail: + msg: user already exists + when: iduser.rc == 0 + - name: create user {{ user }} + command: useradd {{ user }} + + \ No newline at end of file diff --git a/install-apache.yml b/install-apache.yml new file mode 100644 index 0000000..78bf7b7 --- /dev/null +++ b/install-apache.yml @@ -0,0 +1,24 @@ +--- +# name : le nom du playbook (apporte de la clarté au code) +- name: "Apache Installation" + # hosts : la liste des machines sur lesquels nous allons travailler + hosts: 1-1.practice-k8s.cloud + # tasks : une liste d’instructions à dérouler + tasks: + - name: "Install apache package" + # module pour l’installation du package + dnf: + # Les differentes options + name: "httpd" + state: "present" + - name: "Start apache service" + service: + name: "httpd" + state: "started" + enabled: yes + - name: "Copy www.html" + copy: + src: "www.html" + dest: "/var/www/html" + owner: "apache" + group: "apache" diff --git a/intranet-pass.yml b/intranet-pass.yml new file mode 100644 index 0000000..13cdc04 --- /dev/null +++ b/intranet-pass.yml @@ -0,0 +1,6 @@ +$ANSIBLE_VAULT;1.1;AES256 +65376531313239623939643133356639373562356264326464396437313436376562626435333164 +6364363234356264353131366165656564376264306162360a303431616164613666646564663030 +35646439613736383763663831613130383536353934333331393031316333656666363163383066 +3639623834353531350a363035633661396438643332393331373536623163373265346333623832 +35613039623163646536646164336139336231643031666364393934316461653163 diff --git a/inventory.conf.j2 b/inventory.conf.j2 new file mode 100644 index 0000000..08cbe57 --- /dev/null +++ b/inventory.conf.j2 @@ -0,0 +1,8 @@ +# inventory.conf.j2 +Alias /inventaire /var/www/html/inventory + +# Donne des droits d’accès à tout le monde + + Order Allow,Deny + Allow from All + diff --git a/inventory.ini b/inventory.ini new file mode 100644 index 0000000..7f64a2e --- /dev/null +++ b/inventory.ini @@ -0,0 +1,6 @@ +[labs] +1-1.practice-k8s.cloud +1-2.practice-k8s.cloud + +#[all:vars] +#ansible_ssh_user=root diff --git a/jinja2.yml b/jinja2.yml new file mode 100644 index 0000000..df08cf2 --- /dev/null +++ b/jinja2.yml @@ -0,0 +1,8 @@ +- name: "Generate html file for each host" + hosts: all + connection: local + tasks: + - name: "html file generation" + template: + src: "template-net.html.j2" + dest: "{{playbook_dir}}/{{inventory_hostname}}.html" diff --git a/jinja3.yml b/jinja3.yml new file mode 100644 index 0000000..f1aad34 --- /dev/null +++ b/jinja3.yml @@ -0,0 +1,8 @@ +- name: "Generate html file for each host" + hosts: all + tasks: + - name: "html file generation" + template: + src: "template-net.html.j2" + dest: "{{playbook_dir}}/{{inventory_hostname}}.html" + connection: local diff --git a/jinja4.yml b/jinja4.yml new file mode 100644 index 0000000..8cc91f4 --- /dev/null +++ b/jinja4.yml @@ -0,0 +1,21 @@ +--- +- name: "Generate html file for each host" + hosts: all + gather_facts: yes + vars: + host_inventory: "1-1.practice-k8s.cloud" + inventory_dir: "/var/www/html/inventory" + tasks: + - name: "Create template directory" + file: + path: "{{inventory_dir}}" + owner: "apache" + group: "apache" + mode: "0755" + state: "directory" + delegate_to: "{{host_inventory}}" + - name: "html file generation" + template: + src: "template-net.html.j2" + dest: "{{inventory_dir}}/{{inventory_hostname}}.html" + delegate_to: "{{host_inventory}}" \ No newline at end of file diff --git a/jinja5.yml b/jinja5.yml new file mode 100644 index 0000000..f775c3c --- /dev/null +++ b/jinja5.yml @@ -0,0 +1,22 @@ +--- +- name: "Generate html file for each host" + hosts: all + gather_facts: yes + vars: + host_inventory: "1-1.practice-k8s.cloud" + inventory_dir: "/var/www/html/inventory" + tasks: + - name: "Create template directory" + file: + path: "{{inventory_dir}}" + owner: "apache" + group: "apache" + mode: "0755" + state: "directory" + delegate_to: "{{host_inventory}}" + run_once: yes + - name: "html file generation" + template: + src: "template-net.html.j2" + dest: "{{inventory_dir}}/{{inventory_hostname}}.html" + delegate_to: "{{host_inventory}}" \ No newline at end of file diff --git a/magic-variable.yml b/magic-variable.yml new file mode 100644 index 0000000..e2282d2 --- /dev/null +++ b/magic-variable.yml @@ -0,0 +1,8 @@ +--- +- name: playbook directory demo + hosts: all + gather_facts: false + tasks: + - name: print current playbook directory + ansible.builtin.debug: + var: playbook_dir \ No newline at end of file diff --git a/new-vault.key b/new-vault.key new file mode 100644 index 0000000..fbcf12d --- /dev/null +++ b/new-vault.key @@ -0,0 +1 @@ +toto diff --git a/new_facts.yaml b/new_facts.yaml new file mode 100644 index 0000000..70a5ccc --- /dev/null +++ b/new_facts.yaml @@ -0,0 +1,7 @@ +--- +- hosts: all + tasks: + - name: show IP address + debug: + msg: > + This host uses IP address {{ ansible_facts['default_ipv4']['address'] }} \ No newline at end of file diff --git a/old_facts.yaml b/old_facts.yaml new file mode 100644 index 0000000..ef0e2a3 --- /dev/null +++ b/old_facts.yaml @@ -0,0 +1,7 @@ +--- +- hosts: all + tasks: + - name: show IP address + debug: + msg: > + This host uses IP address {{ ansible_default_ipv4.address }} \ No newline at end of file diff --git a/partial-vault.yml b/partial-vault.yml new file mode 100644 index 0000000..ea2fab8 --- /dev/null +++ b/partial-vault.yml @@ -0,0 +1,8 @@ +user: "alex" +pass : !vault | + $ANSIBLE_VAULT;1.1;AES256 + 31643465373363646639363831636564363362663631653566353139343466653438333830636332 + 6137626364373038626663636630363366326631656532320a383761626130343037393762376638 + 31363666616134633533636133663431396565356462633461373935633634643831376430306563 + 6334613131626562370a633263366539653439383434303966616432313933313962366335323831 + 6264 diff --git a/register.yml b/register.yml new file mode 100644 index 0000000..4f63c9a --- /dev/null +++ b/register.yml @@ -0,0 +1,15 @@ +--- +- name: register + hosts: all + gather_facts: no + tasks: + - name: starting httpd + service: name=httpd state=started enabled=yes + + - name: httpd status + command: service httpd status + register: httpd_status + + - name: httpd status output + debug: + var: httpd_status diff --git a/secrets.yml b/secrets.yml new file mode 100644 index 0000000..6b5d761 --- /dev/null +++ b/secrets.yml @@ -0,0 +1,6 @@ +$ANSIBLE_VAULT;1.1;AES256 +38383735373833656365663734343531316138336138666630303862323934656636343332393036 +6234343036336563393132336461356139353331396663310a356334363534316232306161323933 +61333435333964363066363237313664393366643661363637373936636235623563306630636335 +3537303166333038330a393762396435313463653833323933323230633864633265636137336265 +62393538656131343262646530626236346334326232303061356264616134336266 diff --git a/template-net.html.j2 b/template-net.html.j2 new file mode 100644 index 0000000..4c077f0 --- /dev/null +++ b/template-net.html.j2 @@ -0,0 +1,12 @@ + + + Machine {{inventory_hostname}} + + +

Cette machine s’appelle {{inventory_hostname}}

+

Ci-dessous la liste de ces adresses :

+ + + \ No newline at end of file diff --git a/variables_example.yaml b/variables_example.yaml new file mode 100644 index 0000000..754816f --- /dev/null +++ b/variables_example.yaml @@ -0,0 +1,9 @@ +--- +- name: create a user using a variable + hosts: all + vars: + user: lisa + tasks: + - name: create a user {{ user }} on host {{ ansible_hostname }} + ansible.builtin.debug: + msg: "{{ user }}" \ No newline at end of file diff --git a/vault.key b/vault.key new file mode 100644 index 0000000..3131e80 --- /dev/null +++ b/vault.key @@ -0,0 +1 @@ +alexandre diff --git a/www.html b/www.html new file mode 100644 index 0000000..e151180 --- /dev/null +++ b/www.html @@ -0,0 +1 @@ +Ansible <> Bonjour ! \ No newline at end of file