Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrjones-plip/ansible-101
https://github.com/mrjones-plip/ansible-101
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mrjones-plip/ansible-101
- Owner: mrjones-plip
- Created: 2015-04-30T15:51:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-30T16:29:14.000Z (over 9 years ago)
- Last Synced: 2024-03-18T18:10:38.426Z (9 months ago)
- Size: 80.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is just a quick and dirty Ansible 101 for interacting with Linux servers.
#Installing Ansible
Via PIP, this will get Ansible up and running on your machine:
```
pip install ansible
```This should also install dependencies, including paramiko, PyYAML, and Jinja2.
You can install Ansible other ways, but I recommend installing via PIP so you can take advantage of any python packages installed by PIP.
#Getting Started
Create an /etc/ansible/hosts file. This will allow you to group hosts together with a group name. For example, your /etc/ansible/hosts file might look like:
```
[local]
localhost[test]
# debian1
100.42.00.10
# debian2
100.42.00.11
# debian3
100.42.00.12
```Time to try your first Ansible command:
```
ansible test -m ping -u root -k
```When you run a playbook, you can specify which group to run that command or playbook on. For the command, just specify in the command itself (such as the example above). In playbooks, you can specify the host either in the playbook itself (i.e., hosts: <$hostgroup> as the first item in the playbook) or by limiting it when you run the playbook:
```
ansible-playbook -l <$hostgroup_or_name> playbook.yml
```By default, Ansible assumes using ssh keys for keyless access. To override that behavior:
```
-u <$username> #overrides the remote username (default: your current username)
-k #prompts for SSH password
```#Roles
Roles are a built-in structured way to organize templates, variables, and tasks in Ansible.```
roles
<$role_name>
templates
<$myTemplate>.j2
tasks
main.yml
vars
main.yml
```Each <$role_name> can be whatever you want it to be, but the underlying structure should be the same. You can have multiple tasks and vars .yml files, and simply include them in the main.yml file and Ansible will incorporate them automatically when it runs.