# Need help with set\_fact at playbook level.

**URL:** <https://forum.ansible.com/t/need-help-with-set-fact-at-playbook-level/28494>\
**Category:** Ansible Developer\
**Created:** [September 4, 2018, 3:19pm UTC](https://forum.ansible.com/t/need-help-with-set-fact-at-playbook-level/28494 "2018-09-04T15:19:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tabletpfb2018](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tabletpfb2018](https://forum.ansible.com/u/tabletpfb2018)\
**Post date:** [September 4, 2018, 3:19pm UTC](https://forum.ansible.com/t/need-help-with-set-fact-at-playbook-level/28494/1 "2018-09-04T15:19:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 4, 2018, 3:20pm UTC](https://forum.ansible.com/t/need-help-with-set-fact-at-playbook-level/28494/2 "2018-09-04T15:20:57Z")

</div>

Just use vars: keyword.

vars:  
&nbsp;&nbsp;int\_serial\_mode: '{{(serial\_mode is defined)|ternary(3, 1)}}'

---

<div class="post-metadata">

**Author:** ![tabletpfb2018](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tabletpfb2018](https://forum.ansible.com/u/tabletpfb2018)\
**Post date:** [September 4, 2018, 4:25pm UTC](https://forum.ansible.com/t/need-help-with-set-fact-at-playbook-level/28494/3 "2018-09-04T16:25:45Z")

</div>

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.
