4 ms·
Yesterday I was playing with ansible, testing to migrate my already made across years scripts. My vote for the one who puts here an elegant solution for someth
by txutxu 13y ago
Yesterday I was playing with ansible, testing to migrate my already made across years scripts.
My vote for the one who puts here an elegant solution for something as simple as:
ssh user@host sed -i '/FOO/ s/FOO*/BAR/' /etc/bla/bla-*
And a raw: command: or shell: does not count as elegant solution for the vote.
The first parts is easy, you just have to learn a new DSL because ansible ignores your .ssh/config.
The sed is easy to replace to with a lineinfile:
But... how can I iterate over the remote files?
I don't like my solution, is not elegant:
- name: Get the list of remote files
raw: printf '['; printf "'%s'," /etc/sysconfig/network-scripts/ifcfg-*; printf ']'
register: p
- name: Apply the change to the list of files
lineinfile: dest={{ item }} regexp=^NETWORKING_IPV6 line='NETWORKING_IPV6=no'
with_items: p.stdout
My impression in general, after my first weekend with ansible: great
But I see my old script to setup a daemon in a chroot, and I see "my" ansible version... and I don't know what to tell (the ansible version just multiplies the lines, in a much more verbose way, that finally looking at it, you have to think and concentrate much more, than looking at my old and direct .sh)
At the end... this is not new:
ssh WORD < SCRIPT
Where WORD comes from your .ssh/config definitions (the inventory) and SCRIPT is up to you to define and organize properly.
But I wish users of my software where so happy first day as I'm with my ansible experience.
- txutxu 13y agoAnd other thing I've learn this weekend. The documentation is great, but there is no "a reference", you have to read 5 or 6 different (long) pages to have an overview of what the DSL is, but the only reference is for the modules, not for the core. You can search for ansible playbooks in sites like github, and... even if you will find a few which do what they say, you will find many "test" repos, and you will find that the 95% of the available code (no from ansibleworks, but by third parties) implement very poor deployments, without even following basic best practices or any security in mind. I (as final user) would like a "cpan" or "rubygems" or whatever of ansible playbooks, more extended than the ansibleworks examples. Where people could share, search, vote, download (ansible get?), etc ansible playbooks. Just suggestions.
- mpdehaan2 13y agoThanks for feedback. I would suggest looking at github.com/ansible/ansible-examples for a fair amount of examples. I think it's generally true of most systems that a lot of the community implemented content is suited to the needs of someone who wrote it. As for content sharing, we might be working on something :) Stay tuned!
- mpdehaan2 13y ago"The first parts is easy, you just have to learn a new DSL because ansible ignores your .ssh/config." use "-c ssh" for the native OpenSSH connection and it will read your SSH config. As far as jumphosts and other options, paramiko will not. "-c ssh" is the default on platforms that support ControlPersist (because it's faster), so this means CentOS 6 is still using paramiko as a default at least for now.
- txutxu 13y agowow, direct support, this does not have price, you made my day. Will research more about the connection options, did go through the available tutorials, and as it did work with the defaults, I did skip the connections part. Thanks for all the efforts put in this project. P.S. A way to iterate over remote files could be nice. Something like with_remote_fileglob: