官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 泾川县| 恩平市| 宝鸡市| 景谷| 石泉县| 龙南县| 丰原市| 蓬莱市| 鄂托克前旗| 呼图壁县| 临沭县| 工布江达县| 汤原县| 黄梅县| 浪卡子县| 疏勒县| 蓬莱市| 新乡市| 五寨县| 拉萨市| 怀仁县| 奉化市| 永丰县| 大丰市| 常山县| 霍邱县| 梧州市| 府谷县| 平乡县| 潼南县| 林西县| 呼伦贝尔市| 宿州市| 昌江| 融水| 天等县| 灵丘县| 安西县| 阿合奇县| 元阳县| 西丰县|