Execution
Date 04 Dec 2025 12:27:25 +0000
Duration 00:02:20.76
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.11
ara 1.7.3 / 1.7.3
Python 3.10.10
Summary
394 Hosts
5 Tasks
789 Results
3 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/create_botstopper_inventory.yaml

---
- name: Delete file if exists and create header
  hosts: localhost
  gather_facts: false
  vars:
    inv_file: /home/ssh-gateway/ansible/kuly/inventory-botstopper-servers.ini
  tasks:
    - name: Delete inventory file if it exists
      ansible.builtin.file:
        path: "{{ inv_file }}"
        state: absent
      run_once: true
    - name: Create file and header
      ansible.builtin.lineinfile:
        path: "{{ inv_file }}"
        line: "[botstoppers]\n"
        create: true
        mode: '0644'
      run_once: true

- name: Playbook to generate inventory with plesk servers only
  hosts: all
  gather_facts: false
  vars:
    inv_file: /home/ssh-gateway/ansible/kuly/inventory-botstopper-servers.ini
  tasks:
    - name: Get servers info
      plesk_info:
      register: pl
    - name: Get the host that has botstopper
      when: pl.botstopper_found
      ansible.builtin.lineinfile:
        path: "{{ inv_file }}"
        line: "{{ inventory_hostname }}"
        insertafter: "[botstoppers]"
      delegate_to: localhost

- name: Add footer
  hosts: localhost
  gather_facts: false
  vars:
    inv_file: /home/ssh-gateway/ansible/kuly/inventory-botstopper-servers.ini
  tasks:
    - name: Add vars
      ansible.builtin.lineinfile:
        path: "{{ inv_file }}"
        line: |
          [botstoppers:vars]
          ansible_user=root
          ansible_port=2233
        insertafter: EOF
      run_once: true
      delegate_to: localhost