Need help with set_fact at playbook level.

Hi all,

I have a playbook that receives a paramer and based in this we need to set a second variable to stablich the number of instances running.

I have used set_fact several times in task and roles such as:

  • set_fact: int_serial_mode=1
  • set_fact:
    int_serial_mode: 3
    when: serial_mode is defined

but if you move to the playbook the following error in produced:

Using /etc/ansible/ansible.cfg as config file
Vault password:
ERROR! ‘set_fact’ is not a valid attribute for a Play

The error appears to have been in ‘/home/admpablofbo/ptransible/ptrevo/mw_ptr_wls_start_servers.yml’: line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

so we can not use set_fact in playbook.

is there any way to use “something similar” to set_fact in playbook. we need to do at playbook level as serial is stablished at this level.

any help wellcome!

best regards, Pablo.

Just use vars: keyword.

vars:
  int_serial_mode: '{{(serial_mode is defined)|ternary(3, 1)}}'

Hi Brian,
brillian!
seems to work using something like:

  • hosts: “{{ nombre_dominio }}:!adm_{{ nombre_dominio }}”

se establece el numero de instancias, por defecto sera en modo rolling, es decir 1 a 1.

serial: “{{ serial_mode | default(1) | int}}”

serial: “{{ int_serial_mode | default(1) | int}}”

roles:

  • role: ptrevo_role_restart_servers
    vars:
  • producto: “{{ nombre_dominio }}”
  • number_of_host: “group.hosts | length”
  • int_serial_mode: ‘{{(parallel_mode is defined)|ternary(10, 1)}}’

thanks so much for your help.

best regards, Pablo.