Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| elearning:workbooks:debian:6:avance:l130:part5 [2020/12/05 10:10] – admin | elearning:workbooks:debian:6:avance:l130:part5 [2023/01/20 07:28] (Version actuelle) – admin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ~~PDF: | ~~PDF: | ||
| - | Version | + | Version |
| Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
| - | ======DOF505 | + | ======LCF805 |
| =====Contenu du Module===== | =====Contenu du Module===== | ||
| - | * **DOF505 | + | * **LCF805 |
| * Contenu du Module | * Contenu du Module | ||
| - | | + | * LAB #1 - Automatiser avec Ansible |
| - | * Arrêter les Machines Virtuelles non Indispensables | + | * 1.1 - Instructions |
| - | | + | * 1.2 - Corrigés |
| - | * 1.1 - Mettre à Jour PowerShell et .NET | + | * Erreur #1 |
| - | * 1.2 - Configurer WinRM | + | * Erreur |
| - | * 1.3 - Consulter les Informations sur WinRM | + | * Erreur |
| - | * 1.4 - Créer un Utilisateur Local pour Ansible | + | * Erreurs |
| - | * LAB #2 - Préparer le Contrôleur Ansible | + | |
| - | * 2.1 - Installer pywinrm | + | |
| - | * 2.2 - Tester la Configuration | + | |
| - | * LAB #3 - Travailler avec Ansible et Windows | + | |
| - | * 3.1 - Obtenir les Informations sur Windows10 | + | |
| - | * 3.2 - Exécuter une Commande | + | |
| - | * 3.3 - Exécuter un script PowerShell | + | |
| - | * 3.4 - Installer un Logiciel avec Chocolatey | + | |
| - | * 3.5 - Créer un Utilisateur Local | + | |
| - | =====Pré-requis Windows===== | + | =====LAB #1 - Automatiser avec Ansible===== |
| - | Ansible est capable de travailler avec les versions de Windows(tm) suivantes | + | Connectez-vous à la machine virtuelle **CentOS_7** |
| - | * Windows(tm) 7, | + | < |
| - | * Windows(tm) 8.1, | + | trainee@traineeXX: |
| - | * Windowst(tm) 10, | + | </ |
| - | * Windows(tm) Server 2008, | + | |
| - | * Windows(tm) 2008 R2, | + | |
| - | * Wondows(tm) 2012, | + | |
| - | * Windows(tm) 2012 R2, | + | |
| - | * Windows(tm) 2016, | + | |
| - | * Windows(tm) 2019. | + | |
| - | Ansible nécessite sur chaque hôte : | + | ====1.1 - Instructions ==== |
| - | * PowerShell 3.0 ou supérieur | + | Il vous est demandé d' |
| - | * Au moins .NET 4.0. | + | |
| - | =====Arrêter les Machines Virtuelles non Indispensables===== | + | * l' |
| + | * la mise à jour éventuelle de firewalld, | ||
| + | * la création d'une règle dans firewalld pour le trafic vers le serveur vsfptd, | ||
| + | * la création sécurisée de deux comptes ftp : | ||
| + | * user : mike | ||
| + | * mot de passe : toto | ||
| + | * user : bob | ||
| + | * mot de passe : tata | ||
| - | Utilisez les commandes suivantes pour arrêter les machines virtuelles **TargetA**, | + | Installez donc Ansible à partir des dépôts |
| < | < | ||
| - | trainee@ansible:~$ exit | + | [trainee@centos7 |
| - | déconnexion | + | Mot de passe : fenestros |
| - | Connection to localhost closed. | + | Dernière connexion |
| - | desktop@serverXX:~$ VBoxManage controlvm TargetA poweroff | + | [root@centos7 |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | [root@centos7 |
| - | desktop@serverXX:~$ VBoxManage controlvm TargetB poweroff | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX:~$ VBoxManage controlvm Web01 poweroff | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX:~$ VBoxManage controlvm Web02 poweroff | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX:~$ VBoxManage controlvm Web03 poweroff | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX:~$ VBoxManage controlvm Web04 poweroff | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| </ | </ | ||
| - | Restaurez l' | + | Vérifiez ensuite la présence |
| < | < | ||
| - | desktop@serverXX:~$ VBoxManage snapshot TargetA restorecurrent | + | [root@centos7 |
| - | Restoring snapshot ' | + | / |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | [root@centos7 |
| - | desktop@serverXX:~$ VBoxManage snapshot TargetB restorecurrent | + | / |
| - | Restoring snapshot ' | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX: | + | |
| - | Restoring snapshot ' | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX: | + | |
| - | Restoring snapshot ' | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX: | + | |
| - | Restoring snapshot ' | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| - | desktop@serverXX: | + | |
| - | Restoring snapshot ' | + | |
| - | 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | + | |
| </ | </ | ||
| - | Mettez la machine virtuelle **Windows10** dans le NatNetwork | + | Afin de vous aider, on vous fournit deux fichiers |
| < | < | ||
| - | desktop@serverXX:~$ VBoxManage controlvm Windows10 nic1 natnetwork NatNetwork | + | [root@centos7 |
| + | --- | ||
| + | - name: ftp server install | ||
| + | hosts: localhost | ||
| + | gather_facts: | ||
| + | become: yes | ||
| + | vars_files: | ||
| + | - users.yml | ||
| + | tasks: | ||
| + | - name: latest vsftpd version | ||
| + | yum: | ||
| + | name: vsftpd | ||
| + | state: latest | ||
| + | - name: latest firewalld version | ||
| + | name: firewalld | ||
| + | state: latest | ||
| + | - name: vsftpd | ||
| + | service: | ||
| + | name vsftpd | ||
| + | enabled: true | ||
| + | state: started | ||
| + | - name: firewalld | ||
| + | service: | ||
| + | name: firewalld | ||
| + | enabled: true | ||
| + | state: started | ||
| + | - name: firewalld allows ftp | ||
| + | firewalld: | ||
| + | permanent: yes | ||
| + | immediate: yes | ||
| + | state: enabled | ||
| + | - name: Create_FTP_users | ||
| + | user: | ||
| + | password: "{{ item.password | password_hash(sha512) }}" | ||
| + | with_items: "{{ ftp_users }}" | ||
| </ | </ | ||
| - | |||
| - | Reconnectez-vous à la machine virtuelle **Ansible** : | ||
| < | < | ||
| - | desktop@serverXX:~$ ssh -l trainee localhost -p 2222 | + | [root@centos7 |
| - | trainee@localhost' | + | Vault password: fenestros |
| - | Linux ansible.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 | + | ftp_users: |
| - | + | | |
| - | The programs included with the Debian GNU/Linux system are free software; | + | - { username: bob, password: tata } |
| - | the exact distribution terms for each program are described in the | + | |
| - | individual files in / | + | |
| - | + | ||
| - | Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent | + | |
| - | permitted by applicable law. | + | |
| - | Last login: Sun Apr 12 10:07:57 2020 from 10.0.2.2 | + | |
| - | trainee@ansible: | + | |
| </ | </ | ||
| - | =====LAB #1 - Préparer Windows 10===== | + | Lors de l' |
| - | Lancez le logiciel **X2Go Client**. Cliquez ensuite sur : | + | < |
| + | [root@centos7 ~]# ansible-playbook vsftpd.yml | ||
| + | | ||
| - | Session > Nouvelle session | + | |
| - | Dans la fenêtre qui s' | + | ERROR! Syntax Error while loading YAML. |
| - | {{ : | ||
| - | Dans le volet de droite, cliquez sur l'icône du serverXX.ittraining.network | + | The error appears to have been in '/ |
| + | be elsewhere in the file depending on the exact syntax problem. | ||
| - | {{ :elearning: | + | The offending line appears to be: |
| - | Renseignez le mot de passe qui vous a été communiqué et cliquez sur le bouton **OK**. | + | - name: latest firewalld version |
| + | name: firewalld | ||
| + | ^ here | ||
| - | Lancez le logiciel VirtualBox sur votre serveur puis lancez la machine virtuelle **Windows10**. | + | exception type: <class 'yaml.scanner.ScannerError'> |
| + | exception: mapping values are not allowed in this context | ||
| + | in "< | ||
| + | </ | ||
| - | ====1.1 - Mettre à Jour PowerShell et .NET==== | + | A vous de jouer ! |
| - | Afin de mettre à jour les versions de PowerShell et .NET, Ansible fournit un script appelé **Upgrade-PowerShell.ps1**. Exécutez PowerShell en tant qu' | + | [isauth account,@admin] |
| - | < | + | ====1.2 - Corrigés==== |
| - | Windows PowerShell | + | |
| - | Copyright (C) Microsoft Corporation. Tous droits réservés. | + | |
| - | Testez le nouveau système multiplateforme PowerShell https:// | + | ===Erreur #1=== |
| - | PS C: | + | Éditez le fichier |
| - | PS C: | + | |
| - | PS C: | + | |
| - | PS C: | + | |
| - | PS C: | + | |
| - | PS C: | + | |
| - | PS C: | + | |
| - | COMMENTAIRES : | + | |
| - | COMMENTAIRES : | + | |
| - | COMMENTAIRES : | + | |
| - | </ | + | |
| - | + | ||
| - | Au cas où, vous pouvez enlever l' | + | |
| < | < | ||
| - | PS C: | + | [root@centos7 ~]# vi vsftpd.yml |
| - | PS C:\Windows\system32> | + | [root@centos7 ~]# cat vsftpd.yml |
| - | PS C:\Windows\system32> | + | --- |
| - | PS C:\Windows\system32> | + | - name: ftp server install |
| - | PS C:\Windows\system32> | + | hosts: localhost |
| - | PS C:\Windows\system32> | + | |
| + | become: yes | ||
| + | vars_files: | ||
| + | | ||
| + | tasks: | ||
| + | | ||
| + | yum: | ||
| + | name: vsftpd | ||
| + | state: latest | ||
| + | | ||
| + | yum: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
| + | name: firewalld | ||
| + | state: latest | ||
| + | | ||
| + | | ||
| + | name vsftpd | ||
| + | enabled: true | ||
| + | state: started | ||
| + | | ||
| + | service: | ||
| + | name: firewalld | ||
| + | enabled: true | ||
| + | state: started | ||
| + | | ||
| + | | ||
| + | permanent: yes | ||
| + | immediate: yes | ||
| + | state: enabled | ||
| + | | ||
| + | user: | ||
| + | password: "{{ item.password | password_hash(sha512) }}" | ||
| + | with_items: "{{ ftp_users }}" | ||
| </ | </ | ||
| - | ====1.2 - Configurer WinRM==== | + | Relancez la commande |
| - | + | ||
| - | Pour mettre en place un **listener** WinRM en HTTP et un **listener** WinRM en HTTPS, créer un certificat auto-signé et activer l' | + | |
| < | < | ||
| - | PS C: | + | [root@centos7 ~]# ansible-playbook vsftpd.yml |
| - | PS C:\Windows\system32> | + | [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ' |
| - | PS C: | + | ERROR! Syntax Error while loading YAML. |
| - | PS C: | + | |
| - | Self-signed SSL certificate generated; thumbprint: 17502EEEAC259F4C76D0F199A4B803E94E980CAD | + | |
| - | + | ||
| - | + | ||
| - | wxf : http:// | + | |
| - | a : http:// | + | |
| - | w : http:// | + | |
| - | lang : fr-FR | + | |
| - | Address | + | |
| - | ReferenceParameters : ReferenceParameters | + | |
| - | + | ||
| - | Ok. | + | |
| + | The error appears to be in '/ | ||
| + | be elsewhere in the file depending on the exact syntax problem. | ||
| + | The offending line appears to be: | ||
| - | PS C:\Windows\system32> | + | name vsftpd |
| + | enabled: true | ||
| + | ^ here | ||
| </ | </ | ||
| - | ====1.3 - Consulter les Informations sur WinRM==== | + | ===Erreur #2=== |
| - | Pour voir la liste des **listeners** ainsi créés, utilisez la commande suivante | + | Editez le fichier |
| < | < | ||
| - | PS C:\Windows\system32> | + | [root@centos7 ~]# vi vsftpd.yml |
| - | Listener | + | [root@centos7 ~]# cat vsftpd.yml |
| - | | + | --- |
| - | | + | - name: ftp server install |
| - | Port = 5985 | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | + | | |
| - | Listener | + | |
| - | | + | name: vsftpd |
| - | | + | state: latest |
| - | Port = 5986 | + | |
| - | | + | yum: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| - | | + | name: firewalld |
| - | | + | |
| - | | + | |
| - | | + | |
| - | + | name: vsftpd <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
| - | PS C:\Windows\system32> | + | enabled: true |
| + | state: started | ||
| + | - name: firewalld | ||
| + | | ||
| + | name: firewalld | ||
| + | enabled: | ||
| + | | ||
| + | | ||
| + | firewalld: | ||
| + | permanent: yes | ||
| + | immediate: yes | ||
| + | state: enabled | ||
| + | | ||
| + | user: | ||
| + | | ||
| + | | ||
| </ | </ | ||
| - | Pour obtenir les informations concernant le certificat, exécutez les commandes suivantes | + | Relancez la commande **ansible-playbook** |
| < | < | ||
| - | PS C:\Windows\system32> | + | [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ' |
| - | PS C: | + | ERROR! vars file users.yml was not found |
| - | + | Could not find file on the Ansible Controller. | |
| - | + | If you are using a module and expect the file to exist on the remote, see the remote_src option | |
| - | PSPath | + | |
| - | | + | |
| - | PSParentPath | + | |
| - | PSChildName | + | |
| - | PSDrive | + | |
| - | PSProvider | + | |
| - | PSIsContainer | + | |
| - | EnhancedKeyUsageList | + | |
| - | DnsNameList | + | |
| - | SendAsTrustedIssuer | + | |
| - | EnrollmentPolicyEndPoint : Microsoft.CertificateServices.Commands.EnrollmentEndPointProperty | + | |
| - | EnrollmentServerEndPoint : Microsoft.CertificateServices.Commands.EnrollmentEndPointProperty | + | |
| - | PolicyId | + | |
| - | Archived | + | |
| - | Extensions | + | |
| - | System.Security.Cryptography.Oid, System.Security.Cryptography.Oid} | + | |
| - | FriendlyName | + | |
| - | IssuerName | + | |
| - | NotAfter | + | |
| - | NotBefore | + | |
| - | HasPrivateKey | + | |
| - | PrivateKey | + | |
| - | PublicKey | + | |
| - | RawData | + | |
| - | SerialNumber | + | |
| - | SubjectName | + | |
| - | SignatureAlgorithm | + | |
| - | Thumbprint | + | |
| - | Version | + | |
| - | Handle | + | |
| - | Issuer | + | |
| - | Subject | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | PS C: | + | |
| </ | </ | ||
| - | Dernièrement pour obtenir des informations concernant le service, exécutez les deux commandes suivantes : | + | ===Erreur #3=== |
| - | < | + | Créez le fichier |
| - | PS C: | + | |
| - | Service | + | |
| - | RootSDDL = O: | + | |
| - | MaxConcurrentOperations = 4294967295 | + | |
| - | MaxConcurrentOperationsPerUser = 1500 | + | |
| - | EnumerationTimeoutms = 240000 | + | |
| - | MaxConnections = 300 | + | |
| - | MaxPacketRetrievalTimeSeconds = 120 | + | |
| - | AllowUnencrypted = false | + | |
| - | Auth | + | |
| - | Basic = true | + | |
| - | Kerberos = true | + | |
| - | Negotiate = true | + | |
| - | Certificate = false | + | |
| - | CredSSP = false | + | |
| - | CbtHardeningLevel = Relaxed | + | |
| - | DefaultPorts | + | |
| - | HTTP = 5985 | + | |
| - | HTTPS = 5986 | + | |
| - | IPv4Filter = * | + | |
| - | IPv6Filter = * | + | |
| - | EnableCompatibilityHttpListener = false | + | |
| - | EnableCompatibilityHttpsListener = false | + | |
| - | CertificateThumbprint | + | |
| - | AllowRemoteAccess = true | + | |
| - | + | ||
| - | PS C: | + | |
| - | Winrs | + | |
| - | AllowRemoteShellAccess = true | + | |
| - | IdleTimeout = 7200000 | + | |
| - | MaxConcurrentUsers = 2147483647 | + | |
| - | MaxShellRunTime = 2147483647 | + | |
| - | MaxProcessesPerShell = 2147483647 | + | |
| - | MaxMemoryPerShellMB = 2147483647 | + | |
| - | MaxShellsPerUser = 2147483647 | + | |
| - | + | ||
| - | PS C: | + | |
| - | </ | + | |
| - | + | ||
| - | ====1.4 - Créer un Utilisateur Local pour Ansible==== | + | |
| - | + | ||
| - | Créez | + | |
| - | + | ||
| - | Exécutez ensuite la commande suivante | + | |
| < | < | ||
| - | PS C: | + | [root@centos7 ~]# vi users.yml |
| - | Service | + | [root@centos7 ~]# cat users.yml |
| - | | + | ftp_users: |
| - | MaxConcurrentOperations = 4294967295 | + | - { username: mike, password: toto } |
| - | MaxConcurrentOperationsPerUser = 1500 | + | - { username: bob, password: tata } |
| - | EnumerationTimeoutms = 240000 | + | |
| - | MaxConnections = 300 | + | |
| - | MaxPacketRetrievalTimeSeconds = 120 | + | |
| - | AllowUnencrypted = false | + | |
| - | Auth | + | |
| - | Basic = true | + | |
| - | Kerberos = true | + | |
| - | Negotiate = true | + | |
| - | Certificate = false | + | |
| - | CredSSP = false | + | |
| - | CbtHardeningLevel = Relaxed | + | |
| - | DefaultPorts | + | |
| - | HTTP = 5985 | + | |
| - | HTTPS = 5986 | + | |
| - | IPv4Filter = * | + | |
| - | IPv6Filter = * | + | |
| - | EnableCompatibilityHttpListener = false | + | |
| - | EnableCompatibilityHttpsListener = false | + | |
| - | CertificateThumbprint | + | |
| - | AllowRemoteAccess = true | + | |
| - | + | ||
| - | PS C:\Windows\system32> | + | |
| </ | </ | ||
| - | Dans la fenêtre | + | Relancez |
| - | + | ||
| - | {{ : | + | |
| - | + | ||
| - | =====LAB #2 - Préparer le Contrôleur Ansible===== | + | |
| - | + | ||
| - | ====2.1 - Installer pywinrm==== | + | |
| - | + | ||
| - | Dans la machine virtuelle **Ansible**, installez le support python pour WinRM : | + | |
| < | < | ||
| - | root@ansible:~# pip3 install " | + | [root@centos7 |
| - | Collecting pywinrm> | + | [root@centos7 ~]# ansible-playbook vsftpd.yml |
| - | Downloading https:// | + | [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ' |
| - | Collecting requests-ntlm> | + | |
| - | | + | |
| - | Collecting xmltodict (from pywinrm> | + | |
| - | Downloading https:// | + | |
| - | Requirement already satisfied: six in / | + | |
| - | Requirement already satisfied: requests> | + | |
| - | Collecting ntlm-auth> | + | |
| - | Downloading https:// | + | |
| - | Requirement already satisfied: cryptography> | + | |
| - | Installing collected packages: ntlm-auth, requests-ntlm, | + | |
| - | Successfully installed ntlm-auth-1.4.0 pywinrm-0.3.0 requests-ntlm-1.1.0 xmltodict-0.12.0 | + | |
| - | </ | + | |
| - | ====2.2 - Tester la Configuration==== | + | PLAY [ftp server install] *********************************************************************************************************************************************** |
| - | Pour tester la configuration, | + | TASK [latest vsftpd version] |
| + | changed: [localhost] | ||
| - | < | + | TASK [latest firewalld version] ***************************************************************************************************************************************** |
| - | root@ansible:~# vi / | + | changed: [localhost] |
| - | root@ansible: | + | |
| - | 127.0.0.1 localhost | + | |
| - | 127.0.1.1 ansible.i2tch.loc | + | |
| - | 10.0.2.9 ansible.i2tch.loc | + | |
| - | 10.0.2.10 | + | |
| - | 10.0.2.11 web01.i2tch.loc web01 | + | |
| - | 10.0.2.12 web02.i2tch.loc web02 | + | |
| - | 10.0.2.13 web03.i2tch.loc web03 | + | |
| - | 10.0.2.14 web04.i2tch.loc web04 | + | |
| - | 10.0.2.15 | + | |
| - | # The following lines are desirable for IPv6 capable hosts | + | TASK [vsftpd] *********************************************************************************************************************************************************** |
| - | ::1 localhost | + | changed: [localhost] |
| - | ff02::1 ip6-allnodes | + | |
| - | ff02::2 ip6-allrouters | + | |
| - | root@ansible: | + | |
| - | déconnexion | + | |
| - | trainee@ansible: | + | |
| - | </ | + | |
| - | Créez ensuite un Inventory file en tant que trainee | + | TASK [firewalld] ******************************************************************************************************************************************************** |
| + | ok: [localhost] | ||
| - | < | + | TASK [firewalld allows ftp] ********************************************************************************************************************************************* |
| - | trainee@ansible:~$ vi inventory | + | ok: [localhost] |
| - | trainee@ansible: | + | |
| - | [windows] | + | |
| - | windows10 | + | |
| - | [windows: | + | TASK [Create_FTP_users] ************************************************************************************************************************************************* |
| - | ansible_user=trainee | + | fatal: [localhost]: |
| - | ansible_password=trainee | + | |
| - | ansible_connection=winrm | + | |
| - | ansible_winrm_server_cert_validation=ignore | + | |
| - | </code> | + | |
| - | Procédez au test : | + | PLAY RECAP ************************************************************************************************************************************************************** |
| - | + | localhost | |
| - | < | + | |
| - | trainee@ansible:~$ ansible windows -i inventory -m win_ping | + | |
| - | windows10 | SUCCESS | + | |
| - | "changed": false, | + | |
| - | " | + | |
| - | } | + | |
| </ | </ | ||
| - | =====LAB #3 - Travailler avec Ansible et Windows===== | + | ===Erreurs |
| - | + | ||
| - | ====3.1 - Obtenir les Informations sur Windows 10==== | + | |
| - | + | ||
| - | De la même façon qu' | + | |
| - | + | ||
| - | < | + | |
| - | trainee@ansible: | + | |
| - | windows10 | SUCCESS => { | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | }, | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | }, | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | { | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | } | + | |
| - | ], | + | |
| - | " | + | |
| - | " | + | |
| - | ], | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | ], | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | ], | + | |
| - | " | + | |
| - | }, | + | |
| - | " | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | ====3.2 - Exécutez une Commande==== | + | |
| - | + | ||
| - | Créez le PlayBook **command.yml** : | + | |
| < | < | ||
| - | trainee@ansible:~$ vi command.yml | + | [root@centos7 |
| - | trainee@ansible:~$ cat command.yml | + | [root@centos7 |
| --- | --- | ||
| - | - name: ipconfig | + | - name: ftp server install |
| - | hosts: | + | hosts: |
| + | gather_facts: | ||
| + | become: yes | ||
| + | vars_files: | ||
| + | - users.yml | ||
| tasks: | tasks: | ||
| - | - name: run ipconfig | + | - name: latest vsftpd version |
| - | | + | |
| - | | + | name: vsftpd |
| - | - debug: var=ipconfig | + | state: latest |
| + | - name: latest firewalld version | ||
| + | | ||
| + | name: firewalld | ||
| + | state: latest | ||
| + | - name: vsftpd | ||
| + | service: | ||
| + | name: vsftpd <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
| + | enabled: true | ||
| + | state: started | ||
| + | - name: firewalld | ||
| + | service: | ||
| + | name: firewalld | ||
| + | enabled: true | ||
| + | state: started | ||
| + | - name: firewalld allows ftp | ||
| + | firewalld: | ||
| + | permanent: yes | ||
| + | immediate: yes | ||
| + | state: enabled | ||
| + | - name: Create_FTP_users | ||
| + | user: | ||
| + | name: "{{ item.username }}" | ||
| + | password: "{{ item.password | password_hash(' | ||
| + | with_items: "{{ ftp_users }}" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
| </ | </ | ||
| - | Exécutez le PlayBook | + | Relancez la commande **ansible-playbook** |
| < | < | ||
| - | trainee@ansible:~$ ansible-playbook | + | [root@centos7 |
| + | [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ' | ||
| - | PLAY [ipconfig] ********************************************************************************************************************************************************* | + | PLAY [ftp server install] *********************************************************************************************************************************************** |
| - | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [latest vsftpd version] ******************************************************************************************************************************************** |
| - | ok: [windows10] | + | ok: [localhost] |
| - | TASK [run ipconfig] ***************************************************************************************************************************************************** | + | TASK [latest firewalld version] ***************************************************************************************************************************************** |
| - | changed: [windows10] | + | ok: [localhost] |
| - | TASK [debug] ************************************************************************************************************************************************************ | + | TASK [vsftpd] *********************************************************************************************************************************************************** |
| - | ok: [windows10] => { | + | ok: [localhost] |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | "", | + | |
| - | " | + | |
| - | "", | + | |
| - | "", | + | |
| - | "Carte Ethernet Ethernet 2 :", | + | |
| - | "", | + | |
| - | " | + | |
| - | " | + | |
| - | "", | + | |
| - | "Carte Ethernet Ethernet :", | + | |
| - | "", | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | ] | + | |
| - | } | + | |
| - | } | + | |
| - | PLAY RECAP ************************************************************************************************************************************************************** | + | TASK [firewalld] |
| - | windows10 | + | ok: [localhost] |
| - | </ | + | |
| - | ====3.3 - Exécuter un script PowerShell==== | + | TASK [firewalld allows ftp] ********************************************************************************************************************************************* |
| + | ok: [localhost] | ||
| - | Créez un script PowerShell pour démarrer le service Windows Update | + | TASK [Create_FTP_users] ************************************************************************************************************************************************* |
| + | changed: [localhost] => (item={u' | ||
| + | changed: [localhost] => (item={u' | ||
| - | < | + | PLAY RECAP ************************************************************************************************************************************************************** |
| - | trainee@ansible:~$ vi script1.ps1 | + | localhost |
| - | trainee@ansible: | + | |
| - | Start-Service -Name wuauserv | + | |
| </ | </ | ||
| - | Créez ensuite un PlayBook appelé **winupdate.yml** : | + | Crypter le fichier users.yml : |
| < | < | ||
| - | trainee@ansible:~$ vi winupdate.yml | + | [root@centos7 |
| - | trainee@ansible:~$ cat winupdate.yml | + | New Vault password: fenestros |
| - | - name: " | + | Confirm New Vault password: fenestros |
| - | hosts: " | + | Encryption successful |
| - | | + | |
| - | tasks: | + | |
| - | - name: " | + | |
| - | script: " | + | |
| </ | </ | ||
| - | Exécutez | + | Consultez |
| < | < | ||
| - | trainee@ansible:~$ ansible-playbook winupdate.yml -i inventory | + | [root@centos7 |
| + | Vault password: | ||
| + | ftp_users: | ||
| + | - { username: mike, password: toto } | ||
| + | - { username: bob, password: tata } | ||
| - | PLAY [PowerShell script] ************************************************************************************************************************************************ | + | [root@centos7 ~]# cat users.yml |
| - | + | $ANSIBLE_VAULT; | |
| - | TASK [Windows Update] *************************************************************************************************************************************************** | + | 30323061313265353234666230373765333865663061626362646332376639356463623238343166 |
| - | changed: [windows10] | + | 3635356261383732373633626230353837393735393933390a323561663963666262343835363166 |
| - | + | 61306137383463303138656131626236633935383031323864396164366139323265653732663834 | |
| - | PLAY RECAP ************************************************************************************************************************************************************** | + | 6130656163356661360a663635333537373961616230353766666130633537323065663161393939 |
| - | windows10 | + | 65353936613539303631373530643536616335356461323735646165616136303839636166663232 |
| + | 38616133393235636632646461346430373966306463636662333431373936633837616336326461 | ||
| + | 38633139616339343865626630333531366138313761663330346231333131346535663761396233 | ||
| + | 35353036373530323636636335336539616433373461653866316138306632323038626266623264 | ||
| + | 6634 | ||
| </ | </ | ||
| - | ====3.4 - Installer un Logiciel avec Chocolatey==== | + | Exécutez le playbook : |
| - | **[[https:// | + | < |
| + | [root@centos7 ~]# ansible-playbook vsftpd.yml --ask-vault-pass | ||
| + | Vault password: fenestros | ||
| + | [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ' | ||
| - | Créez le PlayBook | + | PLAY [ftp server install] ************************************************************************************************************************************************* |
| - | < | + | TASK [latest vsftpd version] ********************************************************************************************************************************************** |
| - | trainee@ansible:~$ vi firefox.yml | + | ok: [localhost] |
| - | trainee@ansible: | + | |
| - | --- | + | |
| - | - name: Install Firefox using Chocolatey | + | |
| - | hosts: all | + | |
| - | tasks: | + | |
| - | - name: Install Firefox | + | |
| - | win_chocolatey: | + | |
| - | name: firefox | + | |
| - | state: present | + | |
| - | </ | + | |
| - | Exécutez le PlayBook | + | TASK [latest firewalld version] ******************************************************************************************************************************************* |
| + | ok: [localhost] | ||
| - | < | + | TASK [vsftpd] ************************************************************************************************************************************************************* |
| - | trainee@ansible:~$ ansible-playbook firefox.yml -i inventory | + | ok: [localhost] |
| - | PLAY [Install Firefox using Chocolatey] ********************************************************************************************************************************* | + | TASK [firewalld] ********************************************************************************************************************************************************** |
| + | ok: [localhost] | ||
| - | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [firewalld allows ftp] *********************************************************************************************************************************************** |
| - | ok: [windows10] | + | ok: [localhost] |
| - | TASK [Install Firefox] ************************************************************************************************************************************************** | + | TASK [Create_FTP_users] *************************************************************************************************************************************************** |
| - | [WARNING]: Chocolatey was missing from this system, so it was installed during this task run. | + | changed: |
| + | changed: [localhost] => (item={u' | ||
| - | changed: [windows10] | + | PLAY RECAP **************************************************************************************************************************************************************** |
| - | + | localhost | |
| - | PLAY RECAP ************************************************************************************************************************************************************** | + | |
| - | windows10 | + | |
| </ | </ | ||
| - | ====3.5 - Créer un Utilisateur Local==== | + | Notez que malgré le fait que le fichier **users.yml** soit crypté, les mots de passe des utilisateurs apparaissent en clair lors de l' |
| - | Créez le PlayBook **user.yml** : | ||
| < | < | ||
| - | trainee@ansible:~$ vi users.yml | + | [root@centos7 |
| - | trainee@ansible:~$ cat users.yml | + | [root@centos7 |
| - | --- | + | ... |
| - | - name: Create a user | + | - name: Create_FTP_users |
| - | hosts: windows | + | |
| - | tasks: | + | name: "{{ item.username }}" # pas d' |
| - | - name: Create Jean | + | password: |
| - | | + | |
| - | name: jean | + | |
| - | password: | + | |
| - | state: present | + | |
| - | | + | |
| - | - utilisateurs | + | |
| </ | </ | ||
| - | Exécutez le PlayBook | + | De cette façon lors de l' |
| < | < | ||
| - | trainee@ansible:~$ ansible-playbook | + | [root@centos7 |
| + | Vault password: fenestros | ||
| + | [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ' | ||
| + | ... | ||
| + | TASK [Create_FTP_users] *************************************************************************************************************************************************** | ||
| + | changed: [localhost] => (item=None) | ||
| + | changed: [localhost] => (item=None) | ||
| - | PLAY [Create a user] **************************************************************************************************************************************************** | + | PLAY RECAP **************************************************************************************************************************************************************** |
| - | + | localhost | |
| - | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | |
| - | ok: [windows10] | + | |
| - | + | ||
| - | TASK [Create Jean] ****************************************************************************************************************************************************** | + | |
| - | changed: [windows10] | + | |
| - | + | ||
| - | PLAY RECAP ************************************************************************************************************************************************************** | + | |
| - | windows10 | + | |
| </ | </ | ||
| - | Vérifiez que le compte a été créé : | + | [/isauth] |
| - | {{ : | + | ----- |
| - | ----- | + | Copyright © 2022 Hugh Norris. |
| - | < | + | |
| - | <div align=" | + | |
| - | Copyright © 2020 Hugh NORRIS | + | |
| - | </ | + | |
| - | </ | + | |