Note for learning Ansible
Background
IaC - Infrastructure as Code
Definition:
- Use the “code” which can be executed by software to present the IT system infrastructure state.
- The system infrastructure will contain middle software deployment, external service, and the cooperation with provision. (Not only Machine and Network)
Benefit:
- Reduce man power to lower the cost.
- Use programization to reach the high quality
- Easily to deploy large scale.
DevOps
Definition:
- Use the close cooperation between Dev (Development) and Ops (Oprations) to shorten the software life cycle.
- For IaC, we can briefly summarize that it is use code to define a state or operation.
- Design rule:
- Use sub-version tool (Git) to do the version control
- Automation tool test
- static test with code analysis
- Asible to test enviroment
- Serverspec to test the machine state
- Use tool to do CI (Continous Integration)
- Use Jenkin to deploy, and then automatically start Ansible to react to real environment
- Co-work with git to synchonize code and deployment immediately.
For sure, IaC can make all the design procedure automatical.
Note : shell script is also an example of IaC, but only for some low effort work. Chef, Puppet, and Ansible are also example.
Ansible
- Created by Red Hat,
- Use Python to state and promote automation for everyone.
- Component:
- Ansible
- when launching a moddule or playbook, use CLI to execute Ansible. After that, we can use all the command after installation by Ansible.
- Inventory [Where do you want to deploy with Ansible]
- the machine list you want to deploy
- group the machine you want to deploy, and can set different parameters for each group
- Module [What do you want to do with Ansible]
- The function that use Ansible to execute.
- OS operation (package installation, update etc)
- file operation (File copy and paste)
- DB operation (MYSQL, Postgresql etc)
- Cloud service operation (AWS, OpenStack etc)
- online machine operation
- Different from normal command, Ansible will check the statement at this timing, and do only the part we have changed. It will be very complex if you use shell.
ansible-doc -l
to check the module that Ansible
- The function that use Ansible to execute.
- Playbook []
- A rundown code to Ansible.
- Different from other automation tool, the statement description of the playbook is not a programming language.
- Use Yaml to state, which just a modification from JSON.
- Yaml is easy to read from both people and machines.
- Ansible