- Security Automation with Ansible 2
- Madhu Akula Akash Mahajan
- 170字
- 2021-07-02 21:59:58
Setting up nginx web server
Setting up nginx is as simple as sudo apt-get install nginx, but configuring for our use case and managing the configuration's automated way is where Ansible gives the power. Let's look at the following snippet of nginx's role from the playbook:
- name: adding nginx signing key
apt_key:
url: http://nginx.org/keys/nginx_signing.key
state: present
- name: adding sources.list deb url for nginx
lineinfile:
dest: /etc/apt/sources.list
line: "deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx"
- name: update the cache and install nginx server
apt:
name: nginx
update_cache: yes
state: present
- name: updating customized templates for nginx configuration
template:
src: "{{ item.src }}"
dest: "{{ item.dst }}"
with_items:
- { src: "templates/defautlt.conf.j2", dst: "/etc/nginx/conf.d/default.conf" }
notify
- start nginx
- startup nginx
In the preceding code snippet, we are adding the signing key, then adding the repository, then installing. This ensures that we can also perform integrity checks while downloading packages from the repositories.
Then, we are using Jinja2 templating to perform the configuration changes, which can be predefined in our configuration before updating in the server.
推薦閱讀
- 數(shù)據(jù)展現(xiàn)的藝術(shù)
- 玩轉(zhuǎn)智能機(jī)器人程小奔
- 基于LabWindows/CVI的虛擬儀器設(shè)計(jì)與應(yīng)用
- Visual FoxPro 6.0數(shù)據(jù)庫(kù)與程序設(shè)計(jì)
- Mastering D3.js
- 智能工業(yè)報(bào)警系統(tǒng)
- 水下無(wú)線傳感器網(wǎng)絡(luò)的通信與決策技術(shù)
- 西門(mén)子變頻器技術(shù)入門(mén)及實(shí)踐
- R Machine Learning Projects
- Salesforce Advanced Administrator Certification Guide
- Mastering Exploratory Analysis with pandas
- 生成對(duì)抗網(wǎng)絡(luò)項(xiàng)目實(shí)戰(zhàn)
- Mastering OpenStack(Second Edition)
- Natural Language Processing and Computational Linguistics
- Eclipse全程指南