Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- - hosts: 127.0.0.1
- connection: local
- tasks:
- - name: Create QEMU VM
- proxmox_kvm:
- node: '{{node}}'
- api_user: root@pam
- api_password: '{{node_pw}}'
- api_host: '{{node}}'
- #ubuntu-16-04 is the hostname of my template
- clone: ubuntu-16-04
- format: raw
- full: yes
- name: '{{hostname}}'
- storage: local-lvm
- timeout: 600
- - name: Wait for changes to sync
- pause:
- seconds: 10
- - name: Start VM
- proxmox_kvm:
- api_user: root@pam
- api_password: '{{node_pw}}'
- api_host: '{{node}}'
- name: '{{hostname}}'
- state: started
- - name: Wait for VM to boot....
- pause:
- seconds: 30
- - hosts: ubuntu-16-04
- gather_facts: false
- remote_user: ubuntu-16-04
- tasks:
- - name: Create user and set password/sudo
- user:
- name: '{{hostname}}'
- groups: 'sudo'
- home: '/home/{{hostname}}'
- #yes, i pass the password to the playbook in cleartext - it's an ugly solution, alright?
- password: '{{ password | password_hash("sha512") }}'
- shell: /bin/bash
- append: yes
- become: yes
- - name: Copy authorized keys
- copy:
- src: /home/ansible/Ansible/files/generic/pubkeys/authorized_keys
- dest: '/home/{{hostname}}/.ssh/'
- owner: '{{hostname}}'
- group: '{{hostname}}'
- mode: 0600
- become: yes
- - name: Set new IP address
- replace:
- path: /etc/network/interfaces
- regexp: 'address 192.168.1.99'
- replace: 'address {{ip}}'
- become: yes
- - name: Update hostname
- replace:
- path: "{{ item }}"
- regexp: 'ubuntu-16-04'
- replace: '{{hostname}}'
- with_items:
- - /etc/hosts
- - /etc/hostname
- become: yes
- - hosts: 127.0.0.1
- connection: local
- tasks:
- #Needed to remove any processes owned by the old user
- - name: Restart VM
- proxmox_kvm:
- api_user: root@pam
- api_password: '{{node_pw}}'
- api_host: '{{node}}'
- name: '{{hostname}}'
- state: restarted
- - name: Wait for VM to boot ...
- pause:
- seconds: 30
- - hosts: '{{hostname}}'
- tasks:
- - name: Remove template user
- user:
- name: ubuntu-16-04
- state: absent
- become: yes
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement