Hi All,
Hope anyone could help me!
Basically i have a playbook that configures sudoers commands for a particular user. In this playbook is a command that has to use a {{ variable }}. This variable differs dependent on the environment i.e. dev/prod.
Content of files:
#In my root directory main.yml is this:
- hosts: all
become: True
roles:
- configure_sudoers
tags:- environment: dev
in my role playbook is this:
- block:
tags:
dev
prod
name: Create sudoers commands for user
blockinfile:
This is only one line so why use blockinfile?
path: “/etc/sudoers.d/user”
create: yes
block: |
user ALL=(ALL) /bin/systemctl status omsagent-{{ workspace_id }}.service
You should definitely use validate to avoid expensive mistakes
In my vars files is this:
workspace_id: this_id_for_dev
workspace_id: this_id_for_prod
This can’t be in the same file.
Example Scenario:
So if i run the main.yml playbook with tag=dev, I want the role to configure sudoers command and only pass in the workspace_id for devThe same would be if i ran the main.yml playbook with tag=prod
It’s not clear if this different option are on the same target machine? Or are there multiple targets that each have a different sudoers file?