# Key Update depending on the OS version

**URL:** <https://forum.ansible.com/t/key-update-depending-on-the-os-version/36831>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [July 12, 2022, 4:12am UTC](https://forum.ansible.com/t/key-update-depending-on-the-os-version/36831 "2022-07-12T04:12:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [July 12, 2022, 4:12am UTC](https://forum.ansible.com/t/key-update-depending-on-the-os-version/36831/1 "2022-07-12T04:12:56Z")

</div>

Hello Folk,

Need one help in updating the key to sshd\_config file depending on the OS version.

I ve folder structure like below

- roles
- sshd
- tasks  
main.yml
- vars  
main.yml
- template  
main.yml

I want to update **/template/main.yml** like

{% if ansible\_distribution\_major\_version == “8”}  
Insert RHEL8 KEY etc/ssh/sshd\_config  
{% if ansible\_distribution\_major\_version == “7”}  
Inset RHEL7 KEY to etc/ssh/sshd\_config  
{% if ansible\_distribution == “Amazon” }

Inset Amazon KEY to etc/ssh/sshd\_config

{% endif %}

my **tasks/main.yml**

- name : Update the key in sshd\_config  
template:  
src: template/sshd.conf.j2  
dest: /etc/ssh/sshd\_config

Can I write KEY in Vars/main.yml and update the /etc/ssh/sshd\_config file. The above is my approach till now but please somebody help me how can I update the sshd\_config file with the key.

Like in **/vars/main.yml**

RHEL8\_KEY = xyz

RHEL7\_KEY = abc  
RHEL6\_KEY = mno  
AMAZON\_KEY = amazon

Regards

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [July 12, 2022, 5:19am UTC](https://forum.ansible.com/t/key-update-depending-on-the-os-version/36831/2 "2022-07-12T05:19:52Z")

</div>

Thank you for all your help always … I found the solution for the above

{% if ansible\_distribution\_major\_version == “8”}  
{{ RHEL8\_KEY }}  
{% if ansible\_distribution\_major\_version == “7”}  
{{ RHEL7\_KEY }}  
{% if ansible\_distribution == “Amazon” }  
{{ AMZN\_KEY }}  
{% endif %}
