[ansible-project] Key Update depending on the OS version

32 views
Skip to first unread message

Prady A

unread,
Jul 12, 2022, 12:13:47 AM7/12/22
to ansible...@googlegroups.com
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


      

Prady A

unread,
Jul 12, 2022, 1:20:48 AM7/12/22
to ansible...@googlegroups.com
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 %}
Reply all
Reply to author
Forward
0 new messages