I love the new in order to carry me if my questions are a little basic.
Scenario:
I have several groups of remote hosts, such as [EPC] [Clients] and [Testers]. I can configure them the way I want.
Problem:
I need to write a playbook that, at startup, asks the user for inventory at runtime. As an example, when the player starts, the user should be prompted as follows: "Enter the number of EPCs you want to configure" "Enter the number of clients you want to configure" "Enter the number of testers you want to configure"
What is going to happen:
Now, for example, the user enters 2.5 and 8, respectively. Now in the textbook only the first 2 nodes in the [EPC] group, the first 5 nodes in the [Clients] group and the first 7 nodes in the [Testers] group should be addressed. I don’t want to create a large number of subgroups, for example, if I have 20 EPCs, then I don’t want to define 20 groups for my EPCs, I want some dynamic resources that should automatically configure machines according to user input at runtime using the parameter vars_prompt or something like that
Let me publish part of my play for a better understanding of what is going to happen:
- hosts: epcs
vars_prompt:
name: "what is your name?"
quest: "what is your quest?"
gather_facts: no
tasks:
- name: Check if path exists
stat: path=/home/khan/Desktop/tobefetched/file1.txt
register: st
- name: It exists
debug: msg='Path existence verified!'
when: st.stat.exists
- name: It doesn't exist
debug: msg="Path does not exist"
when: st.stat.exists == false
- name: Copy file2 if it exists
fetch: src=/home/khan/Desktop/tobefetched/file2.txt dest=/home/khan/Desktop/fetched/ flat=yes
when: st.stat.exists
- name: Run remotescript.sh and save the output of script to output.txt on the Desktop
shell: cd /home/imran/Desktop; ./remotescript.sh > output.txt
- name: Find and replace a word in a file placed on the remote node using variables
shell: cd /home/imran/Desktop/tobefetched; sed -i 's/{{name}}/{{quest}}/g' file1.txt
tags:
- replace
@gli I tried your solution, I have a group in my inventory called test with two nodes in it. When I enter 0..1 , I get:
TASK: [echo sequence] *********************************************************
changed: [vm2] => (item=some_prefix0)
changed: [vm1] => (item=some_prefix0)
changed: [vm1] => (item=some_prefix1)
changed: [vm2] => (item=some_prefix1)
, 1..2, :
TASK: [echo sequence] *********************************************************
changed: [vm2] => (item=some_prefix1)
changed: [vm1] => (item=some_prefix1)
changed: [vm2] => (item=some_prefix2)
changed: [vm1] => (item=some_prefix2)
, 4..5 (, , :
TASK: [echo sequence] *********************************************************
changed: [vm1] => (item=some_prefix4)
changed: [vm2] => (item=some_prefix4)
changed: [vm1] => (item=some_prefix5)
changed: [vm2] => (item=some_prefix5)
. !