|
--- |
|
|
|
# playbook for local run by Packer |
|
|
|
- name: "ansible playbook for Ubuntu" |
|
hosts: all |
|
gather_facts: yes |
|
|
|
vars: |
|
package_install: [ |
|
{ add_item: 'lsof' }, |
|
{ add_item: 'dos2unix' }, |
|
{ add_item: 'vim' }, |
|
{ add_item: 'make' }, |
|
{ add_item: 'jq' }, |
|
{ add_item: 'tcpdump' }, |
|
{ add_item: 'socat' }, |
|
{ add_item: 'expect' }, |
|
{ add_item: 'sshfs' }, |
|
{ add_item: 'gnupg2' }, |
|
{ add_item: 'inotify-tools' }, |
|
{ add_item: 'apparmor-utils' }, |
|
{ add_item: 'monitoring-plugins-common' }, |
|
{ add_item: 'monitoring-plugins-basic' }, |
|
{ add_item: 'ca-certificates' }, |
|
{ add_item: 'lsb-release' }, |
|
{ add_item: 'acl' } |
|
] |
|
package_remove: [ |
|
{ del_item: 'telnet' } |
|
] |
|
create_folders: [ |
|
{ dir: '/opt/data/', mode: '0775', owner: 'root', group: 'root' }, |
|
{ dir: '/home/ubuntu/downloads/', mode: '0700', owner: 'ubuntu', group: 'ubuntu' }, |
|
{ dir: '/home/ubuntu/upload/', mode: '0700', owner: 'ubuntu', group: 'ubuntu' }, |
|
{ dir: '/root/tmp/', mode: '0700', owner: 'root', group: 'root' }, |
|
{ dir: '/mnt/sshfs/', mode: '0775', owner: 'root', group: 'root' } |
|
] |
|
newuser_name: "cluster" |
|
newuser_home: "/opt/cluster" |
|
|
|
tasks: |
|
|
|
- name: "checks and debug" |
|
block: |
|
- name: "OS check" |
|
assert: |
|
that: |
|
- ansible_os_family == "Debian" |
|
- ansible_architecture in ['aarch64'] |
|
- name: "Display hostname" |
|
debug: |
|
msg: "inventory_hostname {{ inventory_hostname }}" |
|
- name: "cloud init files" |
|
block: |
|
- name: "wait for cloud-init vmhost.fact" |
|
wait_for: |
|
path: /root/welcome.txt |
|
search_regex: Welcome |
|
become: true |
|
- name: "wait for cust-blacklist.conf" |
|
wait_for: |
|
path: /etc/modprobe.d/cust-blacklist.conf |
|
search_regex: blacklist |
|
- name: "wait for cloud-init vmhost.fact" |
|
wait_for: |
|
path: /etc/ansible/facts.d/vmhost.fact |
|
- name: "cloud init mod" |
|
block: |
|
- name: "Gather all facts of cloud init" |
|
cloud_init_data_facts: |
|
filter: status |
|
register: res |
|
until: "res.cloud_init_data_facts.status.v1.stage is defined and not res.cloud_init_data_facts.status.v1.stage" |
|
retries: 50 |
|
delay: 5 |
|
|
|
- name: "system config" |
|
block: |
|
- name: "create new user" |
|
ansible.builtin.user: |
|
name: "{{ newuser_name }}" |
|
comment: "clust user" |
|
home: "{{ newuser_home }}" |
|
shell: /usr/bin/bash |
|
create_home: false |
|
- name: "homedir for {{ newuser_name }}" |
|
ansible.builtin.file: |
|
path: "{{ newuser_home }}" |
|
state: directory |
|
mode: "0775" |
|
owner: "{{ newuser_name}}" |
|
group: "{{ newuser_name }}" |
|
- name: "files and folders" |
|
block: |
|
- name: "create common folders" |
|
ansible.builtin.file: |
|
path: "{{ item.dir }}" |
|
state: directory |
|
mode: "{{ item.mode }}" |
|
owner: "{{ item.owner }}" |
|
group: "{{ item.group }}" |
|
with_items: "{{ create_folders }}" |
|
become: true |
|
|
|
- name: "software" |
|
block: |
|
- name: "install OS packages" |
|
ansible.builtin.package: |
|
name: "{{ item.add_item }}" |
|
state: present |
|
retries: 3 |
|
with_items: "{{ package_install }}" |
|
become: true |
|
tags: |
|
- software |
|
- name: "remove OS packages" |
|
ansible.builtin.package: |
|
name: "{{ item.del_item }}" |
|
state: absent |
|
with_items: "{{ package_remove }}" |
|
become: true |
|
tags: |
|
- software |
|
- name: "patch" |
|
ansible.builtin.apt: |
|
name: "*" |
|
state: latest |
|
become: true |
|
tags: |
|
- software |
|
|
|
- name: "Finish up" |
|
block: |
|
- name: "create readme" |
|
ansible.builtin.copy: |
|
dest: /home/ubuntu/welcome.txt |
|
mode: 0644 |
|
content: | |
|
# --- packer image details --- |
|
# distro: {{ ansible_distribution }} {{ ansible_distribution_version }} {{ ansible_architecture }} |
|
# ansible: {{ ansible_version }} |
|
# python: {{ ansible_playbook_python }} |
|
- name: "debug note" |
|
debug: |
|
msg: "-- playbook.yml has finished --" |
Dude, I f*cking love you! This gist just rescued me from 16 hours of QEMU and VMware Fusion Tech Preview hell trying to get a basic packer Ubuntu box built on an M1 Mac so I can friggin' iterate on my ansible code locally using Vagrant without firing up cloud machines all over the place.
CAN I BUY YOU A BEER?