first-playbook.yml 950 Bytes
Newer Older
1
---
2 3
- name: My First Playbook
  hosts: all
4
  tasks:
5 6
    - name: Ping my hosts
      ansible.builtin.ping:
7

8 9 10
    - name: Print message through dedug modune
      ansible.builtin.debug:
        msg: Hello world
11

12 13 14 15 16 17 18 19 20
    - name: Install and run service in block
      when: ansible_facts["distribution"] == "Ubuntu"
      become: true # just use sudo for task in this block
      block:
        - name: Install some packages
          ansible.builtin.apt:
            name:
              - neofetch
              - ufw
21
            state: present
22 23 24 25 26 27 28 29 30 31 32 33 34 35
        - name: Active service
          ansible.builtin.service:
            name: ufw
            state: started
            enabled: true
      rescue:
        - name: Rescue block
          ansible.builtin.debug:
            msg: "error"
          when: ansible_failed_task.name != "Install some packages"
      always:
        - name: Always block
          ansible.builtin.debug:
            msg: "finish"