Number of loops from command line

Hello,

i have question. Can i specify number of loops from command line --extra_vars? II want specify number of password to be generated.

Thanks for answers.

Jakub Kafka

Of course, with variables you can do almost everyting.

  - debug: var=item
    with_sequence: end={{ number }}

ansible-playbook -e number=3

Please see loop control index_var on loop documentation

Thanks, thats work, bud i have another problem. Here is my code. If i loop more than 2, how can i these 2(and more) results, pass to file. it only pass 1.

- gather_facts: false
  hosts: localhost
  tasks:
    - set_fact:
        db: "{{ lookup('password', '/dev/null chars=ascii_letters,digits length=32') }}"
        usr: "{{ lookup('password', '/dev/null chars=ascii_letters,digits length=39') }}"
        password: "{{ lookup('password', '/dev/null chars=ascii_letters,digits length=21') + '' }}"
      with_sequence: end={{ number }}
    - local_action: shell echo "{{ db }}__{{ usr }} {{ db }} {{ password }}" >> /tmp/pass_pokus3

Dne středa 20. března 2019 17:16:29 UTC+1 Kai Stian Olstad napsal(a):

you are overwriting the variables on each loop, and then you are NOT
looping the shell action. Remove the set fact and use the lookups and
loop directly on the shell action.