|
| 1 | +--- |
| 2 | +title: Ansible Logs Integration Guide |
| 3 | +description: Forward Ansible execution logs to OpenObserve using Fluent Bit for real-time search and observability. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +# Integration with Ansible |
| 8 | + |
| 9 | +This guide walks you through forwarding **Ansible logs** from an Ubuntu machine to OpenObserve using Fluent Bit. |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +Ansible doesn’t send logs to external systems by default. This integration configures a local playbook to write logs to a file, and uses Fluent Bit to tail that file and send logs to OpenObserve over HTTP. |
| 14 | + |
| 15 | +## Steps to Integrate |
| 16 | + |
| 17 | +??? "Prerequisites" |
| 18 | + |
| 19 | + - Ubuntu machine (local, virtual machine, or cloud VM) |
| 20 | + - User with `sudo` privileges |
| 21 | + - Basic familiarity with Ansible and Fluent Bit |
| 22 | + - OpenObserve account ([Cloud](https://cloud.openobserve.ai/web/) or [Self-Hosted](../../../quickstart/#self-hosted-installation)) |
| 23 | + - Ansible Installed |
| 24 | + |
| 25 | +??? "Step 1: Configure Ansible log File" |
| 26 | + |
| 27 | + 1. **Configure log output path in `ansible.cfg`**: |
| 28 | + ```ini |
| 29 | + [defaults] |
| 30 | + log_path = /tmp/ansible_log_demo.txt |
| 31 | + ``` |
| 32 | + |
| 33 | +??? "Step 2: Create a Local Ansible Task (Optional)" |
| 34 | + |
| 35 | + 1. **Create a sample playbook**: |
| 36 | + ```bash |
| 37 | + vi local_task.yml |
| 38 | + ``` |
| 39 | + 2. Add the following contents: |
| 40 | + ```yaml |
| 41 | + --- |
| 42 | + - name: Ansible Local Task Demo |
| 43 | + hosts: localhost |
| 44 | + connection: local |
| 45 | + tasks: |
| 46 | + - name: Create a sample file |
| 47 | + ansible.builtin.file: |
| 48 | + path: /tmp/ansible_log_demo.txt |
| 49 | + state: touch |
| 50 | + |
| 51 | + - name: Write a message to the sample file |
| 52 | + ansible.builtin.copy: |
| 53 | + content: "This is a demo log entry from Ansible." |
| 54 | + dest: /tmp/ansible_log_demo.txt |
| 55 | + ``` |
| 56 | + |
| 57 | + 3. **Run the playbook**: |
| 58 | + ```bash |
| 59 | + ansible-playbook local_task.yml |
| 60 | + ``` |
| 61 | + |
| 62 | + After running, check `/tmp/ansible_log_demo.txt` to confirm logs are generated. |
| 63 | + |
| 64 | +??? "Step 3: Install Fluent Bit on Ubuntu" |
| 65 | + |
| 66 | + 1. **Install Fluent Bit using the official script**: |
| 67 | + ```bash |
| 68 | + curl https://raw.githubusercontent.com/fluent/fluent-bit/master/install.sh | sh |
| 69 | + ``` |
| 70 | + > For manual install or using package managers, refer to [Fluent Bit Docs](https://docs.fluentbit.io/manual/installation/linux/ubuntu) |
| 71 | + |
| 72 | + 2. **Verify installation**: |
| 73 | + ```bash |
| 74 | + fluent-bit --version |
| 75 | + ``` |
| 76 | + |
| 77 | +??? "Step 4: Configure Fluent Bit for Ansible Logs" |
| 78 | + |
| 79 | + 1. **Edit Fluent Bit config file**: |
| 80 | + ```bash |
| 81 | + sudo vi /etc/fluent-bit/fluent-bit.conf |
| 82 | + ``` |
| 83 | + |
| 84 | + 2. **Add the following configuration**: |
| 85 | + ```ini |
| 86 | + [SERVICE] |
| 87 | + Flush 5 |
| 88 | + Daemon Off |
| 89 | + Log_Level info |
| 90 | + |
| 91 | + [INPUT] |
| 92 | + Name tail |
| 93 | + Path /tmp/ansible_log_demo.txt |
| 94 | + Tag ansible.demo |
| 95 | + Refresh_Interval 5 |
| 96 | + |
| 97 | + [OUTPUT] |
| 98 | + Name http |
| 99 | + Match * |
| 100 | + URI /api/<O2_ORG_NAME>/<O2_STREAM_NAME>/_json |
| 101 | + Host <O2_HOST> |
| 102 | + Port 443 |
| 103 | + tls On |
| 104 | + Format json |
| 105 | + Json_date_key _timestamp |
| 106 | + Json_date_format iso8601 |
| 107 | + HTTP_User <O2_USER> |
| 108 | + HTTP_Passwd <O2_PASSWORD> |
| 109 | + compress gzip |
| 110 | + ``` |
| 111 | + |
| 112 | + > Note |
| 113 | + - Replace `<O2_ORG_NAME>`, `<O2_STREAM_NAME>`, `<O2_HOST>`, `<O2_USER>`, and `<O2_PASSWORD>` with your OpenObserve values. |
| 114 | + - Example URI: `/api/default/ansible/_json` for the `default` org and `ansible` stream. |
| 115 | + |
| 116 | +??? "Step 5: Start Fluent Bit" |
| 117 | + |
| 118 | + 1. **Start the Fluent Bit service**: |
| 119 | + ```bash |
| 120 | + sudo systemctl start fluent-bit |
| 121 | + sudo systemctl enable fluent-bit |
| 122 | + ``` |
| 123 | + 2. **Check service status**: |
| 124 | + ```bash |
| 125 | + sudo systemctl status fluent-bit |
| 126 | + ``` |
| 127 | + > Ensure there are no startup errors. Logs will now be tailed and sent to OpenObserve. |
| 128 | + |
| 129 | +??? "Step 6: Verify Logs in OpenObserve" |
| 130 | + |
| 131 | + 1. In your Openobserve instance, Go to **Logs** → select your log stream → Set time range → Click **Run Query** |
| 132 | + |
| 133 | +  |
| 134 | +## Troubleshooting |
| 135 | + |
| 136 | +??? "No logs in OpenObserve?" |
| 137 | + |
| 138 | + - Ensure Fluent Bit is running: `sudo systemctl status fluent-bit` |
| 139 | + - Double-check the HTTP config and authentication |
| 140 | + - Use Fluent Bit in debug mode: |
| 141 | + ```bash |
| 142 | + sudo fluent-bit -c /etc/fluent-bit/fluent-bit.conf -vv |
| 143 | + ``` |
| 144 | + |
| 145 | +??? "Ansible log file not updating?" |
| 146 | + |
| 147 | + - Confirm `log_path` is correctly set in `ansible.cfg` |
| 148 | + - Use verbose flags (`-v`, `-vv`, `-vvv`) to produce more logs |
| 149 | + - Confirm Ansible has permission to write to `/tmp` |
| 150 | + |
| 151 | +??? "Fluent Bit not picking up logs?" |
| 152 | + |
| 153 | + - Make sure the path `/tmp/ansible_log_demo.txt` exists |
| 154 | + - Tail the file manually to confirm updates: |
| 155 | + ```bash |
| 156 | + tail -f /tmp/ansible_log_demo.txt |
| 157 | + ``` |
| 158 | + |
| 159 | + - Adjust `Refresh_Interval` or restart Fluent Bit if needed |
0 commit comments