Re: [ansible-project] selecting file based on hostname

2020-07-10 Thread Abhijeet Kasurde
This is also possible

vars:
file_name_mapping:
amazon: "sudoers.general"
debian: "sudoers.debian"
tasks:
- debug:
msg: "{{ file_name_mapping[ansible_distribution] |
default('sudoers.general')}}"

On Fri, Jul 10, 2020 at 4:13 PM Abhijeet Kasurde 
wrote:

> Do as the following, which will make playbook readable
>
> file_name: sudoers.general
> tasks:
> - name: Set file name when Amazon
> set_fact:
> file_name: "sudoers.aspera"
> when: ansible_distribution == 'amazon'
>
> - name: Set file name when Debian
> set_fact:
> file_name: "sudoers.debian"
> when: ansible_distribution == 'Debian'
>
> - debug:
> msg: "{{ file_name }}"
>
>
>
> On Fri, Jul 10, 2020 at 3:24 PM Krushna Chandra Sahu <
> mailkrus...@gmail.com> wrote:
>
>> Hi Team,
>>
>>   I need a playbook to update the sudoer file based on os distribution. I
>> have written below code but it is failing.
>>
>> - name: Copy sudoers files
>>   copy:
>> src: files/{{ file_name }}
>> dest: /etc/sudoers
>> validate: /usr/sbin/visudo -csf %s
>>   {% if ansible_distribution == "amazon" %}
>>   file_name: 'sudoers.aspera'
>>   {% elif ansible_distribution == "Debian" %}
>>   file_name: 'sudoers.debian'
>>   {% else %}
>>   file_name: 'sudoers.general'
>>   {% end %}
>>
>>
>> The offending line appears to be:
>>
>> validate: /usr/sbin/visudo -csf %s
>>   {% if ansible_distribution == "amazon" %}
>>^ here
>>
>> Regards
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to ansible-project+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/5b6297e0-ffb1-4724-8cd9-4bb2975e2dd0o%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Thanks,
> Abhijeet Kasurde
>


-- 
Thanks,
Abhijeet Kasurde

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFwWkHp4Rz_Ua-6Tz_DNbqPcePH33T376Nj-zNktHn2Osu0ZOQ%40mail.gmail.com.


Re: [ansible-project] selecting file based on hostname

2020-07-10 Thread Abhijeet Kasurde
Do as the following, which will make playbook readable

file_name: sudoers.general
tasks:
- name: Set file name when Amazon
set_fact:
file_name: "sudoers.aspera"
when: ansible_distribution == 'amazon'

- name: Set file name when Debian
set_fact:
file_name: "sudoers.debian"
when: ansible_distribution == 'Debian'

- debug:
msg: "{{ file_name }}"



On Fri, Jul 10, 2020 at 3:24 PM Krushna Chandra Sahu 
wrote:

> Hi Team,
>
>   I need a playbook to update the sudoer file based on os distribution. I
> have written below code but it is failing.
>
> - name: Copy sudoers files
>   copy:
> src: files/{{ file_name }}
> dest: /etc/sudoers
> validate: /usr/sbin/visudo -csf %s
>   {% if ansible_distribution == "amazon" %}
>   file_name: 'sudoers.aspera'
>   {% elif ansible_distribution == "Debian" %}
>   file_name: 'sudoers.debian'
>   {% else %}
>   file_name: 'sudoers.general'
>   {% end %}
>
>
> The offending line appears to be:
>
> validate: /usr/sbin/visudo -csf %s
>   {% if ansible_distribution == "amazon" %}
>^ here
>
> Regards
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5b6297e0-ffb1-4724-8cd9-4bb2975e2dd0o%40googlegroups.com
> 
> .
>


-- 
Thanks,
Abhijeet Kasurde

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFwWkHpr%3DTyYUcnZvE5NutNTsbF72gx%2B03%3DOpgMHMtkPp%3DEN2g%40mail.gmail.com.