Execution
Date
11 Sep 2024 10:24:28 +0100
Duration
00:00:02.80
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
2
Hosts
7
Tasks
7
Results
6
Plays
6
Files
0
Records
File: /home/ssh-gateway/ansible/kuly/create9.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | --- - name: Delete file if exists and create header hosts: localhost gather_facts: false vars: inv_file: /home/ssh-gateway/ansible/kuly/canary-inventory 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: "[canary]\n" create: true mode: '0644' run_once: true - name: Initialize the hosts hosts: localhost gather_facts: false tasks: - name: Initialize plesk_hosts fact if not already initialized ansible.builtin.set_fact: plesk_hosts: [] run_once: true - name: Collect Plesk hosts hosts: all gather_facts: true roles: - plesk tasks: - name: Debug plesk_found variable debug: msg: "plesk_found on {{ inventory_hostname }} is {{ plesk_found | default('not set') }}" - name: Initialize temporary list on localhost ansible.builtin.set_fact: temp_plesk_hosts: [] delegate_to: localhost - name: Append hosts with Plesk to temporary list on localhost when: plesk_found ansible.builtin.set_fact: temp_plesk_hosts: "{{ temp_plesk_hosts + [inventory_hostname] }}" delegate_to: localhost - name: Ensure plesk_hosts is initialized on localhost ansible.builtin.set_fact: plesk_hosts: "{{ hostvars['localhost'].plesk_hosts | default([]) }}" delegate_to: localhost - name: Append temporary list to plesk_hosts ansible.builtin.set_fact: plesk_hosts: "{{ plesk_hosts + temp_plesk_hosts }}" delegate_to: localhost - name: Process and save Plesk hosts hosts: localhost gather_facts: false tasks: - name: Debug collected Plesk hosts debug: msg: "{{ plesk_hosts }}" - name: Debug length of plesk_hosts debug: msg: "Length of plesk_hosts is {{ plesk_hosts | length }}" - name: Select 10 random Plesk hosts ansible.builtin.set_fact: random_plesk_hosts: "{{ plesk_hosts | random(10) if plesk_hosts | length > 10 else plesk_hosts }}" - name: Debug selected random Plesk hosts debug: msg: "{{ random_plesk_hosts }}" - name: Store selected Plesk hosts in a local variable ansible.builtin.set_fact: canary_hosts: "{{ random_plesk_hosts }}" - name: Add selected Plesk hosts to inventory hosts: localhost gather_facts: false vars: inv_file: /home/ssh-gateway/ansible/kuly/canary-inventory tasks: - name: Add selected Plesk hosts to inventory file ansible.builtin.lineinfile: path: "{{ inv_file }}" line: "{{ item }}" insertafter: "[canary]" loop: "{{ canary_hosts }}" run_once: true - name: Add footer hosts: localhost gather_facts: false vars: inv_file: /home/ssh-gateway/ansible/kuly/canary-inventory tasks: - name: Add vars ansible.builtin.lineinfile: path: "{{ inv_file }}" line: | [canary:vars] ansible_user=root ansible_port=2233 insertafter: EOF run_once: true |