Sysadmin > UtilitIes > AnsibLe

ansible configuration management

Installation

View installation instructions

Debian: apt-get install ansible

First Steps

# ansible --version
ansible 1.6.6

Add some host to /etc/ansible/hosts

ansible all --list-hosts
ansible all -m ping
ansible all -a "/bin/date"
ansible gal -m shell -a 'hostname && cat /etc/network/interfaces | grep
bond'
ansible all -m shell -a "rndc retransfer nizza.domain.net"
ansible all -m copy -a "src=/etc/bind.slave/named.conf.local dest=/etc/bind/named.conf.local"

ansible sat -m copy -a "src=/tmp/leap-seconds.list dest=/etc/leap-seconds.list owner=root group=root mode=0644"

Playbooks

Update Debian

---
- hosts: all
  gather_facts: yes
  become: yes

  tasks:
    - name: Perform a dist-upgrade.
      ansible.builtin.apt:
        upgrade: dist
        update_cache: yes

    - name: Check if a reboot is required.
      ansible.builtin.stat:
        path: /var/run/reboot-required
        get_checksum: no
      register: reboot_required_file

    - name: Reboot the server (if required).
      ansible.builtin.reboot:
      when: reboot_required_file.stat.exists == true

    - name: Remove dependencies that are no longer required.
      ansible.builtin.apt:
        autoremove: yes
tnx to Jeff Gerling