# Dynamically set ansible\_network\_os inside playbook fails

**URL:** <https://forum.ansible.com/t/dynamically-set-ansible-network-os-inside-playbook-fails/33817>\
**Category:** Ansible Project\
**Created:** [September 15, 2020, 8:45pm UTC](https://forum.ansible.com/t/dynamically-set-ansible-network-os-inside-playbook-fails/33817 "2020-09-15T20:45:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Miller](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Matt\_Miller](https://forum.ansible.com/u/Matt_Miller)\
**Post date:** [September 15, 2020, 8:45pm UTC](https://forum.ansible.com/t/dynamically-set-ansible-network-os-inside-playbook-fails/33817/1 "2020-09-15T20:45:32Z")

</div>

In the playbook below, I dynamically add\_host and attempt to set ansible\_network\_os for the newly added host. The variable gets set if I use a vars file, but I can’t get it set from within the playbook. Not sure why this is not working …

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 15, 2020, 8:47pm UTC](https://forum.ansible.com/t/dynamically-set-ansible-network-os-inside-playbook-fails/33817/2 "2020-09-15T20:47:48Z")

</div>

remove `vars:` and just put `ansible_network_os` at the same level as `groups`

---

<div class="post-metadata">

**Author:** ![Matt\_Miller](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Matt\_Miller](https://forum.ansible.com/u/Matt_Miller)\
**Post date:** [September 16, 2020, 2:23pm UTC](https://forum.ansible.com/t/dynamically-set-ansible-network-os-inside-playbook-fails/33817/3 "2020-09-16T14:23:57Z")

</div>

Hi Matt,

Thanks for the response.

I did as you suggested, and got different results, but it’s still not working. It’s now complaining about failure to authenticate, which I assume means it’s now happy with the variable assignment, but it broke the authentication.

Full disclosure, without getting into details, I am intentionally using the deprecated authentication method below. The thing is, the authentication works (with deprecation warnings), but not after making the change below. My google searches show tons of examples that I’ve tried to replicate, but I’ll be damned if I can understand what I’m doing wrong.

Thanks,  
Matt

---

<div class="post-metadata">

**Author:** ![Matt\_Miller](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Matt\_Miller](https://forum.ansible.com/u/Matt_Miller)\
**Post date:** [October 30, 2020, 4:15pm UTC](https://forum.ansible.com/t/dynamically-set-ansible-network-os-inside-playbook-fails/33817/4 "2020-10-30T16:15:43Z")

</div>

I did get this working Matt. Your suggestion worked.

Thanks!
