Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ansible@control lesson8]$ cat chad.yml
- ---
- - name: create local index.html file
- hosts: localhost
- tasks:
- - name: create local index.html file
- copy:
- dest: /tmp/index.html
- content: "Welcome to my webserver."
- - name: install and configure web server
- hosts: ansible2.example.com
- vars_files:
- - vars/web_vars
- tasks:
- - name: install packages
- yum:
- name: "{{ web_packages }}"
- when:
- - ansible_distribution in supported_distros
- - ansible_distribution != "Fedora"
- - ansible_distribution_major_version == "8"
- - name: fail when run on fedora or older supported distros
- fail:
- msg: >
- Host {{ ansible_facts['hostname'] }} does not meet minimal requirements
- when:
- ( ansible_distribution not in supported_distros ) or ( ansible_distribution_major_version != "8" )
- - name: configure web content
- block:
- - name: copy index.html
- copy:
- src: /tmp/index.html
- dest: /var/www/html/
- owner: apache
- group: apache
- mode: 0644
- notify: restart httpd
- rescue:
- - debug:
- msg: >
- There was an issue copying the index.html file
- - name: configure firewall
- firewalld:
- service: "{{ item }}"
- state: enabled
- permanent: true
- immediate: true
- loop:
- - http
- - https
- handlers:
- - name: restart httpd
- service:
- name: httpd
- state: restarted
- ...
- [ansible@control lesson8]$
- [ansible@control lesson8]$ cat vars/web_vars
- web_packages:
- - httpd
- - mod_ssl
- supported_distros:
- - "RedHat"
- - "CentOS"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement