On Wednesday, 11 April 2018 15.13.51 CEST Clayton Louden wrote:
> Hi everyone,
>
> Where do you usually put files or templates that are just used in a certain
> play but are not part of a role?
For the most part in a role.
> Currently I do have them just alongside my
> playbooks organised by play
Some file like ssh and gpg public keys is located on top level inside files/ directly.
The reason for this is that it make it easier for people since they don't need to go deep down into a role if they need to change their files or add files.
> This however is a bit awkward when using it in a play since I always have
> to specify the play subfolder in files/ or templates/
>
> - name: Copy extensions.conf
> copy: src=files/someplay/extensions.conf dest=/etc/extensions.conf
>
> Now this can be easily solved by converting that particular playbook into a
> role and then just using 'templates/somethemplate.js' and 'files/somefile'
> without the 'play' subdirectory.
When using template it automatically check the templates folder so you don't need to include templates/, somethemplate.js suffice.
The same are try for copy and the files/ directory in a role.
> That however has the side-effect that I'd
> have a rather stupid playbook that just includes a role, which I find
> rather annoying:
>
> - name: Configure server
> hosts: mysinglehost
> roles:
> - role: custom_configure_server_role
Personally i find this cleaner that having a task.
And if you have more than one host that need it, you only have one place to change the code if needed.
You can leave out role:
roles:
- custom_configure_server_role
> I've heard from other ansible guys that they treat 'everything as a role'.
> Maybe it's just me but I find that opening a playbook just to find out that
> it contains just one custom role a bit redundant. How do you guys usually
> do this?
If the config is very small I sometimes do someting like this since it fast and easy to grasp
- name: Runing check every minute
copy:
content: |
# Managed by Ansible
* * * * * root /usr/local/bin/check
dest: /etc/cron.d/hourly_check
--
Kai Stian Olstad