Skip to content

Instantly share code, notes, and snippets.

@sigmadream
Created Apr 21, 2018
Embed
What would you like to do?
- name: Install Apache Web Server
hosts: '{{ vmname }}'
gather_facts: no
tasks:
- name: Ensure apache is at the latest version
yum: name=httpd state=latest
become: true
- name: Change permissions of /var/www/html
file: path=/var/www/html mode=0777
become: true
- name: Download index.html
get_url:
url: <<HTML FILE>>
dest: /var/www/html/index.html
mode: 0644
- name: Ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
become: true
- name: CREATE VM PLAYBOOK
hosts: localhost
connection: local
gather_facts: False
vars:
dnsname: '{{ vmname }}.westeurope.cloudapp.azure.com'
ip: "{{ lookup ('dig', '{{ dnsname }}') }}"
tasks:
- debug: msg="Public DNS name {{ dnsname }} resolved to IP {{ ip }}. "
- name: Create storage account
azure_rm_storageaccount:
resource_group: '{{ resgrp }}'
name: '{{ vmname }}'
account_type: Standard_LRS
- name: Create security group that allows SSH and HTTP
azure_rm_securitygroup:
resource_group: '{{ resgrp }}'
name: '{{ vmname }}'
rules:
- name: SSH
protocol: Tcp
destination_port_range: 22
access: Allow
priority: 101
direction: Inbound
- name: WEB
protocol: Tcp
destination_port_range: 80
access: Allow
priority: 102
direction: Inbound
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: '{{ resgrp }}'
allocation_method: Static
name: '{{ vmname }}'
domain_name_label: '{{ vmname }}'
- name: Create NIC
azure_rm_networkinterface:
resource_group: '{{ resgrp }}'
name: '{{ vmname }}'
virtual_network: '{{ vnet }}'
subnet: '{{ subnet }}'
public_ip_name: '{{ vmname }}'
security_group: '{{ vmname }}'
- name: Create VM
azure_rm_virtualmachine:
resource_group: '{{ resgrp }}'
name: '{{ vmname }}'
storage_account: '{{ vmname }}'
storage_container: '{{ vmname }}'
storage_blob: '{{ vmname }}.vhd'
network_interfaces: '{{ vmname }}'
vm_size: Standard_A0
admin_username: lab-user
ssh_password_enabled: False
ssh_public_keys:
- path: /home/lab-user/.ssh/authorized_keys
key_data: '<<KEY>>'
image:
offer: Canonical
publisher: UbuntuServer
sku: '16.04-LTS'
version: latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment