Configuring Ansible
redhat.com
redhat.com
It's not an uncommon workflow to have a central "Ansible server" with a service account (hence why Tower exists) that's essentially used as a privileged bastion host in environments where sysadmin laptops don't have a way to reach servers directly.
It's not too hard to figure out how to do this, but probably there isn't much blogging about something like this.
[defaults] inventory = ./inventory/hosts
[defaults]
inventory=./hosts.d
(This is what I use)You just don't want variation in the run depending on what directory you happen to be.
Personally I want an env(1) of something like ANSIBLE_HOME where, if defined, it completely ignores [/usr/local]/etc/ansible/.
First of all, no, don't create an ansible user. Never use generic shared accounts. I mean, you can, but you can also just SSH into root. (You know what the difference between using the -B option and SSHing into root are? There is none.)
Second, either use sssd to enable an SSO system, or bootstrap all your hosts with an SSH CA so you don't have to constantly run jobs to add SSH public keys to all your nodes, which when you eventually start using ephemeral nodes, won't work at all unless it's using a shared account; see above paragraph.
Third, if you're going to use a plaintext inventory, generate it on the fly, and definitely don't write it to a single global root-owned file, because you may want to update it some time, and you may be running ansible more than once on that host at that time.
Fourth, they didn't really go over the anguish of trying to manage system-installed python packages and running Ansible. You need to install and run Ansible in a virtualenv with pinned versions, don't use a system-packaged version.
Five, don't use any complicated logic in your tasks or playbooks, or later you'll be kicking yourself because of how much of a huge pain in the ass it is to debug playbooks and tasks and inventories and filters and the non-standard fake YAML config format and a million other things. Keep it really really simple.
Six, run ansible-pull on a cron job with random jitter every 10-20 minutes, because your system and code will deviate over time, and you won't know it until you try to run Ansible again after 3 months and everything breaks. You'll also want a system to alert you when Ansible fails so you can find out what broke.
Seven, try to make any Ansible you use obsolete by baking Docker images, VM images, system packages, and other versioned immutable infrastructure artifacts. If you start out with that in mind, you may not ever have to touch Ansible once, and may even eventually achieve immutable infrastructure, and what a wonderful world that is. (I'm serious... everyone should be working to remove configuration management from their stack wherever it's feasible)
Indeed. This is what makes a configuration management tool work in practice.
https://twitter.com/search?q=from%3Amoreati%20ansible%20tip&...
https://twitter.com/search?q=from%3Amoreati%20ansible%20gotc...
The infrastructure is provisioned using 90% CloudFormation and the other 10% is Ansible commands for when CF is not enough or when AWS CLI commands allows for better flexibility (i.e. generating SSH keys for EC2 machines and storing the private key in a central store). We make heavy use of the `cloudformation` Ansible-module.
Did you look at EC2 UserData at all when you decided to use Ansible? I asked about this use case on the AWS Slack and someone pointed me at it. I haven't had a look yet but if you've used it as well as Ansible then I'd be curious to know how they compare/how you ended up with Ansible + CF instead.
I have a few deployments using CloudFormation, and in those use CloudFormation::Init [1] to actually setup the EC2 instances (deploy packages, apps, configure local firewall, etc). This kind of grew over time and now involves some (mildly) complex bash and/or powershell scripts which do things that could probably be done with Ansible, but when I started it wasn't obvious how complex that part would eventually get. The split of Ansible vs CloudFormation responsibility also wasn't clear to me, and I favored the simplicity of a single tool, so even though I considered using Ansible, I ended up sticking to CloudFormation::Init.
In retrospect, CloudFormation::Init is pretty much a stand-alone tool, and the only connection it has to AWS and AWS CloudFormation is really just that it reads the metadata from the EC2 API to get its actual configuration (which is just a JSON or YAML blob).
[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGui...
EDIT: To clarify: the ansible-commands runs locally on your machine, or locally on the CI/CD agent - not on any remote machine/EC2 instance.
I know every experienced Windows admin would probably look poorly on my setup, but it feels really good to finally have some level of automation in managing these machines. It took me years to figure out a sane strategy under constraints like: OEM and retail software licenses only, employees retain admin privileges, no corporate network or VPN, unstable IP addresses, and (perhaps most importantly) no budget.
With constraints like that, it would also be a pretty good setup if you provide tech support to family and friends, as long as they trust you to backdoor their laptop.
[1]: https://www.ansible.com/managing-windows-desktops-with-ansib... [2]: https://github.com/crombeen/ansible [3]: https://pagekite.net/
Thanks for the pointer. They certainly have the most fun pricing page I've seen to date: https://pagekite.net/signup/?more=bw
I'd like to do something similar, currently we use a mix of ansible tower (which I don't love) and ansible runs from local machines to manage the infrastructure. I'd rather it all be tied into terraform though, so that we have a single place to manage changes from
Especially around Vault, it never really clicked for me, I fail to see how it helps most of the times, if a user can trigger X that will generate a key on the fly, what prevents a hacker from doing the same, etc...
It's a complexity-compartmentalization trade off, that is usually recommended for better IT sec posture. Allows other stuff [IDS - intrusion detection system] to be built on top more easily.
Basically leads to the secrets in the secret vault mentality, so any time you see a secret not in the vault, you can sound the alarm.
It'll be getting updated with PDF versions of the material and quizzes soon enough.
Plusses: - Supported Ansible modules are usually more reliable and more clearly defined in terms of how they'll function than community cookbooks for Chef are - Upgrades between versions go smoothly - People can just go read your YAML and figure out what it's going to do
Minuses: - It's not code, so if you want to do something more programmatic, you're going to end up with something ugly compared to what you can do in Chef/Puppet's Ruby DSL - It's still a bit immature in terms of comparison to Chef's server offering (Ansible Tower is pretty useless), and the Kitchen/Vagrant/Serverspec stuff is also not as advanced.
Ansible seems to fit well as a replacement for the Chef Zero use case of fire-and-forget provisioning - works well inside Packer or inside of Terraform via a null_resource, but I don't tend to find myself wanting to use it for long-lived machines that in the Chef world benefitted from continually running the cookbooks to help keep config in sync.
If you need code, you're encouraged to write your own module (pure Python, typically)
> Ansible Tower is pretty useless
Why?
Meh, I really like Tower, but maybe that depends on what you're used to.
> It's not code, so if you want to do something more programmatic, you're going to end up with something ugly
this is true, ansibles DSL has its limits and the developers are pretty clear that there are some things that are too complicated for its yaml based syntax. 99% of use cases its great for, if you want that extra 1% then you have to write your own ansible modules (which is actually reasonably straightforward). I dont know chef but puppet has become more and more complicated over the years chasing the more advanced use cases and in many ways thats moved it away from a tool for sysadmins towards a being a tool for specialists so I think Ansibles outlook makes more sense. YMMV.
Yeah, I concur. There aren't too many cases where I can't work around the lack of programmability with some creative templates or what-have-you.
(I wonder if I could render an Ansible task file from a template and then include it...)
Ansible is more like a readable bash on steroids. It's basically a way to distribute and execute Python code into other machines. Unless you have AWX (Tower), or create a custom repeatable delivery, it won't take care of config drift.
Overall, Ansible is much easier to write and understand. It's an extremely powerful tool. Puppet doesn't have any amazing advantages or disadvantages over Ansible (except of the simplicity, which is a large benefit for Ansible).
Ansible tends to be better for jobs you do when a sysadmin wants them done, its really good for scripting repeatable installations, or for doing updates in a consistent fashion on hundreds of machines, adding new users to a bunch of different applications, etc etc.
You can use puppet for ad-hoc jobs, but its not really designed for that it tends to be overly complicated and a bit awkward (imho). You can do drift re-mediation with ansible and run it every 30 mins to fix issues and it will work but its not its real sweet spot.
Personally I would use ansible for both use cases because its simpler, I understand it, and it has a more sysadmin way of thinking, but I know places that use both and that makes sense as well.
You may find Puppet obtuse if all you want is one time provisioning of new hosts. Sometimes you do care about procedural concerns like execution order, and in Puppet you have some influence (e.g. dependency relationships) but not direct control.
You may find Ansible backs you into corners with long lived mutable infrastructure. Configurations may drift, and your ability to run a playbook may depend on the sequence of playbooks previously run on the target. Ansible doesn’t really have a notion of converging on a goal state; it’s closer to scripting. You can have a single idempotent playbook that you run every time, but it’s not opinionated about that.
I'm using it with Vagrant and VirtualBox at the moment, just because that was the easiest way -- if you aren't already using Docker, that is -- to get started (due to available documentation, examples, etc.) but eventually I'd like to use both Docker and my ESXi lab for testing.
Testing w/ bare-metal was always a pain in the ass as I'd constantly need to "reset" the hosts to a specific "known good" starting point. I have everything set up for automated network installs, though, so it only takes 5 minutes or so to wipe and reinstall a physical host.
Now, I'm doing all my Ansible testing against VMs on VirtualBox, running from an image generated by Packer. Those images use the exact same preseed.cfg file I use on the bare-metal host, making it sooooo much easier. I do all my testing on the VMs, make sure everything is correct, and then run it against the physical host once for "verification".