Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.25 KB | None | 0 0
  1. ---
  2. - hosts: 127.0.0.1
  3.   connection: local
  4.   tasks:
  5.   - name: Create QEMU VM
  6.     proxmox_kvm:
  7.       node: '{{node}}'
  8.       api_user: root@pam
  9.       api_password: '{{node_pw}}'
  10.       api_host: '{{node}}'
  11.       #ubuntu-16-04 is the hostname of my template
  12.       clone: ubuntu-16-04
  13.       format: raw
  14.       full: yes
  15.       name: '{{hostname}}'
  16.       storage: local-lvm    
  17.       timeout: 600
  18.   - name: Wait for changes to sync
  19.     pause:
  20.       seconds: 10
  21.   - name: Start VM
  22.     proxmox_kvm:
  23.       api_user: root@pam
  24.       api_password: '{{node_pw}}'
  25.       api_host: '{{node}}'
  26.       name: '{{hostname}}'
  27.       state: started
  28.   - name: Wait for VM to boot....
  29.     pause:
  30.       seconds: 30
  31.  
  32. - hosts: ubuntu-16-04
  33.   gather_facts: false
  34.   remote_user: ubuntu-16-04
  35.   tasks:
  36.   - name: Create user and set password/sudo
  37.     user:
  38.       name: '{{hostname}}'
  39.       groups: 'sudo'
  40.       home: '/home/{{hostname}}'
  41.       #yes, i pass the password to the playbook in cleartext - it's an ugly solution, alright?
  42.       password: '{{ password | password_hash("sha512") }}'
  43.       shell: /bin/bash
  44.       append: yes
  45.     become: yes
  46.   - name: Copy authorized keys
  47.     copy:
  48.         src: /home/ansible/Ansible/files/generic/pubkeys/authorized_keys
  49.         dest: '/home/{{hostname}}/.ssh/'
  50.         owner: '{{hostname}}'
  51.         group: '{{hostname}}'
  52.         mode: 0600
  53.     become: yes    
  54.  
  55.   - name: Set new IP address
  56.     replace:
  57.       path: /etc/network/interfaces
  58.       regexp: 'address 192.168.1.99'
  59.       replace: 'address {{ip}}'
  60.     become: yes
  61.   - name: Update hostname
  62.     replace:
  63.       path: "{{ item }}"
  64.       regexp: 'ubuntu-16-04'
  65.       replace: '{{hostname}}'
  66.     with_items:
  67.      - /etc/hosts
  68.       - /etc/hostname
  69.     become: yes
  70.  
  71. - hosts: 127.0.0.1
  72.   connection: local
  73.   tasks:
  74.  #Needed to remove any processes owned by the old user
  75.   - name: Restart VM
  76.     proxmox_kvm:
  77.       api_user: root@pam
  78.       api_password: '{{node_pw}}'
  79.       api_host: '{{node}}'
  80.       name: '{{hostname}}'
  81.       state: restarted
  82.   - name: Wait for VM to boot ...
  83.     pause:
  84.       seconds: 30
  85.  
  86. - hosts: '{{hostname}}'
  87.   tasks:
  88.   - name: Remove template user
  89.     user:
  90.       name: ubuntu-16-04
  91.       state: absent
  92.     become: yes
  93. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement