Actualiser 01_AnsibleAzure.yaml
This commit is contained in:
+115
-112
@@ -1,113 +1,116 @@
|
|||||||
Créer le fichier infra_azure.yml :
|
|
||||||
- name: Déployer une infrastructure Azure complète
|
- name: Déployer une infrastructure Azure complète
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
vars:
|
vars:
|
||||||
location: "eastus"
|
location: "eastus"
|
||||||
resource_group: "ResourceGroup_Genthon_Fayard"
|
resource_group: "ResourceGroup_Genthon_Fayard"
|
||||||
virtual_network: "VNet_Genthon_Fayard"
|
virtual_network: "VNet_Genthon_Fayard"
|
||||||
subnet: "Subnet_Genthon_Fayard"
|
subnet: "Subnet_Genthon_Fayard"
|
||||||
IP_publique: "PublicIP_Genthon_Fayard"
|
IP_publique: "PublicIP_Genthon_Fayard"
|
||||||
NSG: "NSG_Genthon_Fayard"
|
NSG: "NSG_Genthon_Fayard"
|
||||||
VM: "UbuntuVMGenthonFayard"
|
VM: "UbuntuVMGenthonFayard"
|
||||||
network_interface: "VMNic_Genthon_Fayard"
|
network_interface: "VMNic_Genthon_Fayard"
|
||||||
vm_size: "Standard_DS1_v2"
|
vm_size: "Standard_DS1_v2"
|
||||||
os_type: "Linux"
|
os_type: "Linux"
|
||||||
offer: "UbuntuServer"
|
offer: "UbuntuServer"
|
||||||
publisher: "Canonical"
|
publisher: "Canonical"
|
||||||
sku: "18.04-LTS"
|
sku: "18.04-LTS"
|
||||||
version: "latest"
|
version: "latest"
|
||||||
admin_username: "azureuser"
|
admin_username: "azureuser"
|
||||||
admin_password: "{{ lookup('community.general.random_string', length=20, special=True) }}"
|
admin_password: "{{ lookup('community.general.random_string', length=20, special=True) }}"
|
||||||
vars_files:
|
vars_files:
|
||||||
- secrets.yml # Charger le fichier Vault contenant les variables sensibles
|
- secrets.yml # Charger le fichier Vault contenant les variables sensibles
|
||||||
tasks:
|
tasks:
|
||||||
# Créer un Resource Group
|
# Créer un Resource Group
|
||||||
- name: Créer un Resource Group
|
- name: Créer un Resource Group
|
||||||
azure.azcollection.azure_rm_resourcegroup:
|
azure.azcollection.azure_rm_resourcegroup:
|
||||||
name: "{{ resource_group }}"
|
name: "{{ resource_group }}"
|
||||||
location: "{{ location }}"
|
location: "{{ location }}"
|
||||||
# Créer un Virtual Network
|
|
||||||
- name: Créer un Virtual Network
|
# Créer un Virtual Network
|
||||||
azure.azcollection.azure_rm_virtualnetwork:
|
- name: Créer un Virtual Network
|
||||||
name: "{{ virtual_network }}"
|
azure.azcollection.azure_rm_virtualnetwork:
|
||||||
resource_group: "{{ resource_group }}"
|
name: "{{ virtual_network }}"
|
||||||
location: "{{ location }}"
|
resource_group: "{{ resource_group }}"
|
||||||
address_prefixes:
|
location: "{{ location }}"
|
||||||
- "10.0.0.0/16"
|
address_prefixes:
|
||||||
# Créer un Subnet
|
- "10.0.0.0/16"
|
||||||
- name: Créer un Subnet
|
|
||||||
azure.azcollection.azure_rm_subnet:
|
# Créer un Subnet
|
||||||
name: "{{ subnet }}"
|
- name: Créer un Subnet
|
||||||
resource_group: "{{ resource_group }}"
|
azure.azcollection.azure_rm_subnet:
|
||||||
virtual_network: "{{ virtual_network }}"
|
name: "{{ subnet }}"
|
||||||
address_prefix: "10.0.1.0/24"
|
resource_group: "{{ resource_group }}"
|
||||||
# Créer une IP publique
|
virtual_network: "{{ virtual_network }}"
|
||||||
- name: Créer une IP publique
|
address_prefix: "10.0.1.0/24"
|
||||||
azure.azcollection.azure_rm_publicipaddress:
|
|
||||||
name: "{{ IP_publique }}"
|
# Créer une IP publique
|
||||||
resource_group: "{{ resource_group }}"
|
- name: Créer une IP publique
|
||||||
allocation_method: Static
|
azure.azcollection.azure_rm_publicipaddress:
|
||||||
location: "{{ location }}"
|
name: "{{ IP_publique }}"
|
||||||
# Créer un Network Security Group
|
resource_group: "{{ resource_group }}"
|
||||||
- name: Créer un Network Security Group (NSG)
|
allocation_method: Static
|
||||||
azure.azcollection.azure_rm_securitygroup:
|
location: "{{ location }}"
|
||||||
name: "{{ NSG }}"
|
|
||||||
resource_group: "{{ resource_group }}"
|
# Créer un Network Security Group
|
||||||
location: "{{ location }}"
|
- name: Créer un Network Security Group (NSG)
|
||||||
rules:
|
azure.azcollection.azure_rm_securitygroup:
|
||||||
- name: Allow-SSH
|
name: "{{ NSG }}"
|
||||||
protocol: Tcp
|
resource_group: "{{ resource_group }}"
|
||||||
destination_port_range: 22
|
location: "{{ location }}"
|
||||||
access: Allow
|
rules:
|
||||||
direction: Inbound
|
- name: Allow-SSH
|
||||||
priority: 100
|
protocol: Tcp
|
||||||
source_address_prefix: '*'
|
destination_port_range: 22
|
||||||
destination_address_prefix: '*'
|
access: Allow
|
||||||
- name: Allow-RDP
|
direction: Inbound
|
||||||
protocol: Tcp
|
priority: 100
|
||||||
destination_port_range: 3389
|
source_address_prefix: '*'
|
||||||
access: Allow
|
destination_address_prefix: '*'
|
||||||
direction: Inbound
|
- name: Allow-RDP
|
||||||
priority: 110
|
protocol: Tcp
|
||||||
source_address_prefix: '*'
|
destination_port_range: 3389
|
||||||
destination_address_prefix: '*'
|
access: Allow
|
||||||
- name: AllowICMP
|
direction: Inbound
|
||||||
priority: 1002
|
priority: 110
|
||||||
direction: Inbound
|
source_address_prefix: '*'
|
||||||
access: Allow
|
destination_address_prefix: '*'
|
||||||
protocol: ICMP
|
- name: AllowICMP
|
||||||
source_port_range: '*'
|
priority: 1002
|
||||||
destination_port_range: '*'
|
direction: Inbound
|
||||||
source_address_prefix: '*'
|
access: Allow
|
||||||
destination_address_prefix: '*'
|
protocol: ICMP
|
||||||
# Créer une interface réseau (NIC)
|
source_port_range: '*'
|
||||||
- name: Créer une interface réseau pour la VM
|
destination_port_range: '*'
|
||||||
azure.azcollection.azure_rm_networkinterface:
|
source_address_prefix: '*'
|
||||||
name: "{{ network_interface }}"
|
destination_address_prefix: '*'
|
||||||
resource_group: "{{ resource_group }}"
|
|
||||||
ANSIBLE Page 3
|
# Créer une interface réseau (NIC)
|
||||||
resource_group: "{{ resource_group }}"
|
- name: Créer une interface réseau pour la VM
|
||||||
location: "{{ location }}"
|
azure.azcollection.azure_rm_networkinterface:
|
||||||
security_group: "{{ NSG }}"
|
name: "{{ network_interface }}"
|
||||||
virtual_network: "{{ virtual_network }}"
|
resource_group: "{{ resource_group }}"
|
||||||
subnet_name: "{{ subnet }}"
|
location: "{{ location }}"
|
||||||
ip_configurations:
|
security_group: "{{ NSG }}"
|
||||||
- name: "ipconfig"
|
virtual_network: "{{ virtual_network }}"
|
||||||
public_ip_address_name: "{{ IP_publique }}"
|
subnet_name: "{{ subnet }}"
|
||||||
# Créer une VM Linux (exemple avec Ubuntu)
|
ip_configurations:
|
||||||
- name: Créer une VM Linux Ubuntu
|
- name: "ipconfig"
|
||||||
azure.azcollection.azure_rm_virtualmachine:
|
public_ip_address_name: "{{ IP_publique }}"
|
||||||
name: "{{ VM }}"
|
|
||||||
resource_group: "{{ resource_group }}"
|
# Créer une VM Linux (exemple avec Ubuntu)
|
||||||
location: "{{ location }}"
|
- name: Créer une VM Linux Ubuntu
|
||||||
vm_size: "{{ vm_size }}"
|
azure.azcollection.azure_rm_virtualmachine:
|
||||||
admin_username: "{{ admin_username }}"
|
name: "{{ VM }}"
|
||||||
admin_password: "{{ admin_password }}"
|
resource_group: "{{ resource_group }}"
|
||||||
network_interfaces: "{{ network_interface }}"
|
location: "{{ location }}"
|
||||||
os_type: "{{ os_type }}"
|
vm_size: "{{ vm_size }}"
|
||||||
image:
|
admin_username: "{{ admin_username }}"
|
||||||
offer: "{{ offer }}"
|
admin_password: "{{ admin_password }}"
|
||||||
publisher: "{{ publisher }}"
|
network_interfaces: "{{ network_interface }}"
|
||||||
sku: "{{ sku }}"
|
os_type: "{{ os_type }}"
|
||||||
version: "{{ version }}"
|
image:
|
||||||
|
offer: "{{ offer }}"
|
||||||
|
publisher: "{{ publisher }}"
|
||||||
|
sku: "{{ sku }}"
|
||||||
|
version: "{{ version }}"
|
||||||
Reference in New Issue
Block a user