Created
January 19, 2020 10:36
-
-
Save hasenbalg/c6cb097cd55d648a13814c1ff49bb717 to your computer and use it in GitHub Desktop.
Ansible blockinline with item list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# without a marker for each iteration blockinlist will only write the last list entry in the file | |
# this example shares the directories huhu and haha in the /tmp dir via samba | |
- hosts: all | |
vars: | |
shared_folders: | |
- {name: "huhu", path: "/tmp/huhu"} | |
- {name: "haha", path: "/tmp/haha"} | |
tasks: | |
- name: check if shared folders exist | |
become: yes | |
file: | |
path: "{{ item.path }}" | |
mode: 0777 | |
owner: nobody | |
group: nogroup | |
state: directory | |
with_items: "{{ shared_folders }}" | |
- name: configure samba shares | |
become: yes | |
blockinfile: | |
path: /etc/samba/smb.conf | |
# this is the important part | |
marker: "### config for {{ item.name }}" | |
block: | | |
[{{ item.name }}] | |
comment = About {{ item.name }} | |
browseable = yes | |
path = {{ item.path }} | |
guest ok = yes | |
read only = no | |
create mask = 0777 | |
with_items: "{{ shared_folders }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this! I had to tweak it a bit to keep sections from being repeatedly added.
Instead of
I had to add the `{mark}' variable like so: