Execution
Date 09 Sep 2024 15:23:40 +0100
Duration None
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.4
ara 1.7.1 / 1.7.1
Python 3.10.10
Summary
137 Hosts
7 Tasks
625 Results
2 Plays
11 Files
0 Records

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

---
- name: Delete file if exists and create header
  hosts: localhost
  gather_facts: false
  vars:
    inv_file: /home/ssh-gateway/ansible/kuly/plesks.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: "[plesks]\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/plesks.ini
  roles:
    - plesk
    - imunify360
  tasks:
    - name: If plesk server add name to list
      when: plesk_found and imunify_found
      ansible.builtin.lineinfile:
        path: "{{ inv_file }}"
        line: "{{ inventory_hostname }}"
        insertafter: "[plesks]"
      delegate_to: localhost

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