Home Automate EVERYTHING with Ansible!
Post
Cancel

Automate EVERYTHING with Ansible!

Automate EVERYTHING with Ansible!

Ansible. Need I say more? Well, maybe, if you’ve never heard of it. Ansible is a simple IT automation that anyone can use. You can Automate anything with an SSH conne

Watch Video

See all the hardware I recommend at https://l.technotim.live/gear

Don’t forget to check out the 🚀Launchpad repo with all of the quick start source files.

install

1
2
3
sudo apt update
sudo apt install ansible
sudo apt install sshpass

hosts

1
2
3
4
5
[ubuntu]
server-01
server-02
192.168.0.100
192.168.0.1002

commands

command with module

1
ansible -i ./inventory/hosts ubuntu -m ping --user someuser --ask-pass

command with playbook

1
ansible-playbook ./playbooks/apt.yml --user someuser --ask-pass --ask-become-pass -i ./inventory/hosts

playbooks

apt.yml

1
2
3
4
5
6
7
- hosts: "*"
  become: yes
  tasks:
    - name: apt
      apt:
        update_cache: yes
        upgrade: 'yes'

qemu-guest-agent.yml

1
2
3
4
5
6
7
8
9
- name: install latest qemu-guest-agent
  hosts: "*"
  tasks:
    - name: install qemu-guest-agent
      apt:
        name: qemu-guest-agent
        state: present
        update_cache: true
      become: true

zsh.yml

1
2
3
4
5
6
7
8
9
- name: install latest zsh on all hosts
  hosts: "*"
  tasks:
    - name: install zsh
      apt:
        name: zsh
        state: present
        update_cache: true
      become: true

timezone.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- name: Set timezone and configure timesyncd
  hosts: "*"
  become: yes
  tasks:
  - name: set timezone
    shell: timedatectl set-timezone America/Chicago

  - name: Make sure timesyncd is stopped
    systemd:
      name: systemd-timesyncd.service
      state: stopped

  - name: Copy over the timesyncd config
    template: src=../templates/timesyncd.conf dest=/etc/systemd/timesyncd.conf

  - name: Make sure timesyncd is started
    systemd:
      name: systemd-timesyncd.service
      state: started

timesyncd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
NTP=192.168.0.4
FallbackNTP=time.cloudflare.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
This post is licensed under CC BY 4.0 by the author.