Just done my first ansible deployment today; very impressive how easy it is to get up and running! Thank you for releasing it.
I have a few bits of feedback and questions.
- lineinfile regexp appears to be anchored, i.e. you need to do
lineinfile regexp=“.*foo”
to match foo other than at start of line. I’m not sure if this is intentional, since the docs show examples like regexp=^SELINUX= (explicitly anchoring the line)
My guess is this is an artefact of using Python’s re.match instead of re.search.
re.match(“b”,“abc”)
re.match(“.*b”,“abc”)
<_sre.SRE_Match object at 0x1005a9f38>
re.search(“b”,“abc”)
<_sre.SRE_Match object at 0x1005a9ed0>
- Wishlist: it would be nice to have playbook action as an array, to save having to name every single micro step:
- name: install some packages
action:
- apt pkg=snmpd state=latest
- apt pkg=snmp-mibs-downloader state=latest
- …
(however, the ‘with_items’ syntax can be used in that particular case)
- What’s the recommended way of dealing with a tree of files? The best I can come up with so far is to list them one by one with ‘with_items’
- name: add SNMP files
action: copy src=snmp-files$item dest=$item mode=644
with_items:
- /usr/share/snmp/mibs/MD-RAID-MIB.txt
- /usr/share/snmp/mibs/HACKING-SNMP-MIB.txt
- /usr/share/snmp/mibs/SMARTCTL-MIB.txt
- /usr/lib/snmpd-connector-lib.sh
- /usr/lib/hacking-bash.sh
Have I missed a trick here?
One solution would be a construct like with_items which recursively iterates over a source directory, which would be simple to implement, albeit slow.
A faster solution would be for the copy/template module to work recursively, check all the md5sums in one go, and upload all the changes files in one go; but I suspect that would be quite a lot more work.
- Any suggestions for how to say “ensure this directory is empty apart from the files I just installed”? Usage case is /etc/freeradius where there’s a load of default junk installed by the package manager, which I want to remove. Of course I can just remove it entirely (state=absent) and then install the files I want, but that is an operation I would not want to run repeatedly.
Thanks again,
Brian.
Replies inline.
Just done my first ansible deployment today; very impressive how easy it is
to get up and running! Thank you for releasing it.
I have a few bits of feedback and questions.
1. lineinfile regexp appears to be anchored, i.e. you need to do
lineinfile regexp=".*foo"
In 0.8, it is no longer anchored -- and that's been true for a while.
It releases Friday.
2. Wishlist: it would be nice to have playbook action as an array, to save
having to name every single micro step:
- name: install some packages
action:
- apt pkg=snmpd state=latest
- apt pkg=snmp-mibs-downloader state=latest
This is not going to happen, but "name" is optional, so just don't
specify the name.
- ...
(however, the 'with_items' syntax can be used in that particular case)
3. What's the recommended way of dealing with a tree of files? The best I
can come up with so far is to list them one by one with 'with_items'
This, in 0.8
https://github.com/ansible/ansible/blob/devel/examples/playbooks/loop_plugins.yml
(or just use local_action with rsync if you need recursion)
4. Any suggestions for how to say "ensure this directory is empty apart from
the files I just installed"? Usage case is /etc/freeradius where there's a
load of default junk installed by the package manager, which I want to
remove. Of course I can just remove it entirely (state=absent) and then
install the files I want, but that is an operation I would not want to run
repeatedly.
No method for this exists, or will exist. Sorry.
Thanks for your quick reply.
In 0.8, it is no longer anchored – and that’s been true for a while.
It releases Friday.
Great. (BTW I am using 0.7.2 from apt repo)
- Wishlist: it would be nice to have playbook action as an array, to save
having to name every single micro step:
- name: install some packages
action:
- apt pkg=snmpd state=latest
- apt pkg=snmp-mibs-downloader state=latest
This is not going to happen, but “name” is optional, so just don’t
specify the name.
I see. The example you linked seems to use another syntax as well:
tasks:
- file: dest=/etc/fooapp state=directory
- copy: src=$item dest=/etc/fooapp/ owner=root mode=600
with_fileglob: /playbooks/files/fooapp/*
which is slightly briefer than
- action: file dest=/etc/fooapp state=directory
- action: copy src=$item dest=/etc/fooapp/ owner=root mode=600
Cheers,
Brian.
Thanks for your quick reply.
In 0.8, it is no longer anchored – and that’s been true for a while.
It releases Friday.
Great. (BTW I am using 0.7.2 from apt repo)
- Wishlist: it would be nice to have playbook action as an array, to save
having to name every single micro step:
- name: install some packages
action:
- apt pkg=snmpd state=latest
- apt pkg=snmp-mibs-downloader state=latest
This is not going to happen, but “name” is optional, so just don’t
specify the name.
I see. The example you linked seems to use another syntax as well:
tasks:
- file: dest=/etc/fooapp state=directory
- copy: src=$item dest=/etc/fooapp/ owner=root mode=600
with_fileglob: /playbooks/files/fooapp/*
which is slightly briefer than
- action: file dest=/etc/fooapp state=directory
- action: copy src=$item dest=/etc/fooapp/ owner=root mode=600
Cheers,
Brian.
This is a new shortcut syntax, which was introduced last week or so.
Serge