first commit
This commit is contained in:
		
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| { | ||||
|     "ansible.python.interpreterPath": "/bin/python3.11" | ||||
| } | ||||
							
								
								
									
										12
									
								
								1-1.practice-k8s.cloud.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								1-1.practice-k8s.cloud.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <html> | ||||
|   <head> | ||||
|     <title>Machine 1-1.practice-k8s.cloud</title> | ||||
|   </head> | ||||
|   <body> | ||||
|     <p>Cette machine s’appelle 1-1.practice-k8s.cloud</p> | ||||
|     <p>Ci-dessous la liste de ces adresses :</p> | ||||
|     <ul> | ||||
|      IP : 10.75.40.101 | ||||
|     </ul> | ||||
|   </body> | ||||
| </html> | ||||
							
								
								
									
										12
									
								
								1-2.practice-k8s.cloud.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								1-2.practice-k8s.cloud.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <html> | ||||
|   <head> | ||||
|     <title>Machine 1-2.practice-k8s.cloud</title> | ||||
|   </head> | ||||
|   <body> | ||||
|     <p>Cette machine s’appelle 1-2.practice-k8s.cloud</p> | ||||
|     <p>Ci-dessous la liste de ces adresses :</p> | ||||
|     <ul> | ||||
|      IP : 10.76.132.143 | ||||
|     </ul> | ||||
|   </body> | ||||
| </html> | ||||
							
								
								
									
										23
									
								
								ansible.cfg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								ansible.cfg
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										20
									
								
								apache-inventaire.conf.tag.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								apache-inventaire.conf.tag.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										19
									
								
								apache-inventaire.conf.yml 
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								apache-inventaire.conf.yml 
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										22
									
								
								apache-when-handler.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								apache-when-handler.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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" | ||||
							
								
								
									
										23
									
								
								apache-when.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								apache-when.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										18
									
								
								command-output-test.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								command-output-test.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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" | ||||
|  | ||||
							
								
								
									
										1
									
								
								fichier-variables.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								fichier-variables.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| varfile: file | ||||
							
								
								
									
										18
									
								
								filter-1.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								filter-1.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 }}" | ||||
|  | ||||
							
								
								
									
										20
									
								
								iden-creat-user.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								iden-creat-user.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 }} | ||||
|  | ||||
|   | ||||
							
								
								
									
										24
									
								
								install-apache.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								install-apache.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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" | ||||
							
								
								
									
										6
									
								
								intranet-pass.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								intranet-pass.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| $ANSIBLE_VAULT;1.1;AES256 | ||||
| 65376531313239623939643133356639373562356264326464396437313436376562626435333164 | ||||
| 6364363234356264353131366165656564376264306162360a303431616164613666646564663030 | ||||
| 35646439613736383763663831613130383536353934333331393031316333656666363163383066 | ||||
| 3639623834353531350a363035633661396438643332393331373536623163373265346333623832 | ||||
| 35613039623163646536646164336139336231643031666364393934316461653163 | ||||
							
								
								
									
										8
									
								
								inventory.conf.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								inventory.conf.j2
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| # inventory.conf.j2  | ||||
| Alias /inventaire /var/www/html/inventory  | ||||
|   | ||||
| # Donne des droits d’accès à tout le monde  | ||||
| <Directory /var/www/html/inventory/>  | ||||
|   Order Allow,Deny  | ||||
|   Allow from All  | ||||
| </Directory> | ||||
							
								
								
									
										6
									
								
								inventory.ini
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								inventory.ini
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| [labs] | ||||
| 1-1.practice-k8s.cloud | ||||
| 1-2.practice-k8s.cloud | ||||
|  | ||||
| #[all:vars] | ||||
| #ansible_ssh_user=root | ||||
							
								
								
									
										8
									
								
								jinja2.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								jinja2.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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" | ||||
							
								
								
									
										8
									
								
								jinja3.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								jinja3.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										21
									
								
								jinja4.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								jinja4.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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}}" | ||||
							
								
								
									
										22
									
								
								jinja5.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								jinja5.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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}}" | ||||
							
								
								
									
										8
									
								
								magic-variable.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								magic-variable.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										1
									
								
								new-vault.key
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								new-vault.key
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| toto | ||||
							
								
								
									
										7
									
								
								new_facts.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								new_facts.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| --- | ||||
| - hosts: all | ||||
|   tasks: | ||||
|   - name: show IP address | ||||
|     debug: | ||||
|       msg: > | ||||
|         This host uses IP address {{ ansible_facts['default_ipv4']['address'] }} | ||||
							
								
								
									
										7
									
								
								old_facts.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								old_facts.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| --- | ||||
| - hosts: all | ||||
|   tasks: | ||||
|   - name: show IP address | ||||
|     debug: | ||||
|       msg: > | ||||
|         This host uses IP address {{ ansible_default_ipv4.address }} | ||||
							
								
								
									
										8
									
								
								partial-vault.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								partial-vault.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| user: "alex" | ||||
| pass : !vault | | ||||
|           $ANSIBLE_VAULT;1.1;AES256 | ||||
|           31643465373363646639363831636564363362663631653566353139343466653438333830636332 | ||||
|           6137626364373038626663636630363366326631656532320a383761626130343037393762376638 | ||||
|           31363666616134633533636133663431396565356462633461373935633634643831376430306563 | ||||
|           6334613131626562370a633263366539653439383434303966616432313933313962366335323831 | ||||
|           6264 | ||||
							
								
								
									
										15
									
								
								register.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								register.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
							
								
								
									
										6
									
								
								secrets.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								secrets.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| $ANSIBLE_VAULT;1.1;AES256 | ||||
| 38383735373833656365663734343531316138336138666630303862323934656636343332393036 | ||||
| 6234343036336563393132336461356139353331396663310a356334363534316232306161323933 | ||||
| 61333435333964363066363237313664393366643661363637373936636235623563306630636335 | ||||
| 3537303166333038330a393762396435313463653833323933323230633864633265636137336265 | ||||
| 62393538656131343262646530626236346334326232303061356264616134336266 | ||||
							
								
								
									
										12
									
								
								template-net.html.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								template-net.html.j2
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <html> | ||||
|   <head> | ||||
|     <title>Machine {{inventory_hostname}}</title> | ||||
|   </head> | ||||
|   <body> | ||||
|     <p>Cette machine s’appelle {{inventory_hostname}}</p> | ||||
|     <p>Ci-dessous la liste de ces adresses :</p> | ||||
|     <ul> | ||||
|      IP : {{ ansible_facts['default_ipv4']['address'] }} | ||||
|     </ul> | ||||
|   </body> | ||||
| </html> | ||||
							
								
								
									
										9
									
								
								variables_example.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								variables_example.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 }}" | ||||
		Reference in New Issue
	
	Block a user