Ansible is mainly used for automize Linux/windows servers provisioning and operation, however from version 2.1 there is support module for network related devices. In order to test it I have first install ansible in my mac: There are several ways to install ansible, but the mostly common used on mac is homebrew an pip. Github.com/MWGriffin/ansible-playbooks is one of the first to use Ansible to install Macs. The last change was made in 2013. It provides playbooks for installation of php and others from zip file that may now be available as Homebrew packages. It copies from URLS such as into the /.ansible-downloads/ folder it creates. Ansiblebecomemethod: enable ansibleuser: cisco ansiblepassword: cisco ansiblebecomepass: cisco ansiblenetworkos: ios ansibleconnection: networkcli tasks: name: port security iosconfig: lines: interface fastEthernet0/4; switchport mode access; switchport port security; switchport security maximum 1; switchport port security mac. A password can be used to authenticate to remote Linux machines, but this is not supported for Mac or OSX systems. The public key must be pre-installed or copied to the remote machine. Installing the extension adds the following Ansible task which runs a given Playbook: When Ansible automation engine is located on an Agent machine.
From my early days with Solaris Jumpstart to more modern tools like Ansible, I’ve always been big on configuration management. For a long time I only thought about CM in terms of server configuration. Even when I was running Linux as my primary operating system, I never really thought about using CM to keep it configured properly. It wasn’t until I switch over to MacOS about 5 years ago I started to think about using CM to configure my laptop. I was pretty big on Ansible at the time, so I started digging into it. After I came across a couple of Ansible roles by Jeff Geerling for installing Homebrew and App Store applications, I setup my own repository for configuring MacOS.
Mac Ansible Config
Creating the Playbook
The first step is to set up the Ansible playbook. Since I am running it on my local laptop, the connection needs to be set to local. I put all my variables in a file called
config.yaml
, and then define the two roles that I want to run.You also need to set up a
requirements.yml
file to install the roles.Finally, create an inventory file with the following:
Creating the config.yaml
![Ansible installation guide Ansible installation guide](/uploads/1/2/4/8/124812319/102519155.jpg)
In the
config.yaml
, you need to set up the following variables:The
mas
package is needed for installing the Mac App Store applications, and can be used to lookup the ID for an app.First Run
When running the playbook for the first time on a fresh MacOS install, there are a couple of things that need to be done. First thing is to log in to the Mac App Store so that when the mas role runs it can install what is necessary. The other is to get a terminal and run the following commands:
The osascript command helps setup the correct permissions for the terminal to be able to run the Ansible automation in the
ansible-playbook
command.Ansible Apt Install
Additional Configuration
In addition to Jeff Geerling’s roles, I created a role local to the playbook called local-config, which I use to do additional configuration to my Mac, including cloning and syncing my dotfiles, setting up Python, Ruby, and Node, and cleaning up and reordering my dock.
Now, when I need to reinstall or configure a new laptop, I can have everything back to the way that I want it in about an hour without having to download everything. One of these days, I need to figure out how to configure everything that gets installed (Dropbox, 1Password, etc).