{"id":3198,"sha1":"fffb48f0ccfbfadb03d5e342f52d510511c14918","playbook":{"id":1719,"items":{"plays":3,"tasks":8,"results":65,"hosts":21,"files":6,"records":0},"arguments":{"version":null,"verbosity":2,"private_key_file":"/home/ssh-gateway/.ssh/id_rsa","remote_user":"root","connection":"ssh","timeout":null,"ssh_common_args":null,"sftp_extra_args":null,"scp_extra_args":null,"ssh_extra_args":null,"ask_pass":false,"connection_password_file":null,"force_handlers":false,"flush_cache":false,"become":false,"become_method":"sudo","become_user":null,"become_ask_pass":false,"become_password_file":null,"tags":["all"],"skip_tags":[],"check":false,"diff":false,"inventory":["/home/ssh-gateway/ansible/kuly/canary-prod-hosts"],"listhosts":false,"subset":null,"extra_vars":"Not saved by ARA as configured by 'ignored_arguments'","vault_ids":[],"ask_vault_pass":false,"vault_password_files":[],"forks":20,"module_path":null,"syntax":false,"listtasks":false,"listtags":false,"step":false,"start_at_task":null,"args":["create6.yaml"]},"labels":[{"id":1,"name":"remote_user:root"},{"id":2,"name":"check:False"},{"id":3,"name":"tags:all"}],"started":"2024-09-11T12:40:29.436501+01:00","ended":"2024-09-11T12:40:41.818812+01:00","duration":"00:00:12.382311","name":null,"ansible_version":"2.16.4","client_version":"1.7.1","python_version":"3.10.10","server_version":"1.7.1","status":"completed","path":"/home/ssh-gateway/ansible/kuly/create6.yaml","controller":"ssh-gw-4.layershift.com","user":"root"},"content":"---\n- name: Manage inventory files\n  hosts: localhost\n  gather_facts: false\n  vars:\n    files:\n      - /home/ssh-gateway/ansible/kuly/canary-inventory\n      - /tmp/plesk_hosts.txt\n  tasks:\n    - name: Delete existing inventory and temp files\n      ansible.builtin.file:\n        path: \"{{ item }}\"\n        state: absent\n      loop: \"{{ files }}\"\n\n    - name: Create inventory file and header\n      ansible.builtin.lineinfile:\n        path: /home/ssh-gateway/ansible/kuly/canary-inventory\n        line: \"[canary]\\n\"\n        create: true\n        mode: '0644'\n\n- name: Collect Plesk hosts\n  hosts: all\n  gather_facts: false\n  roles:\n    - plesk\n  tasks:\n    - name: Save Plesk hostnames to a temp file\n      when: plesk_found\n      ansible.builtin.lineinfile:\n        path: /tmp/plesk_hosts.txt\n        line: \"{{ inventory_hostname }}\"\n        create: true\n        mode: '0644'\n      delegate_to: localhost\n\n- name: Process Plesk hosts\n  hosts: localhost\n  gather_facts: false\n  tasks:\n    - name: Read Plesk hosts from file\n      ansible.builtin.set_fact:\n        plesk_hosts_content: \"{{ lookup('file', '/tmp/plesk_hosts.txt') }}\"\n\n    - name: Select 10 random Plesk hosts\n      ansible.builtin.set_fact:\n        random_plesk_hosts: >\n          {% set number_to_select = 10 %}\n          {% set lines = plesk_hosts_content.split('\\n') %}\n          {% if lines | length > number_to_select %}\n            {% set shuffled = lines | shuffle %}\n            {{ shuffled[:number_to_select] }}\n          {% else %}\n            {{ lines }}\n          {% endif %}\n\n    - name: Write selected Plesk hosts to inventory file\n      ansible.builtin.copy:\n        dest: /home/ssh-gateway/ansible/kuly/canary-inventory\n        content: |\n          [canary]\n          {% for host in random_plesk_hosts %}\n          {{ host }}\n          {% endfor %}\n          [canary:vars]\n          ansible_user=root\n          ansible_port=2233\n        mode: '0644'\n","created":"2024-09-11T12:40:29.454364+01:00","updated":"2024-09-11T12:40:29.454388+01:00","path":"/home/ssh-gateway/ansible/kuly/create6.yaml"}