Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ansible@control lesson8]$ cat lab2.yaml
- ---
- - name: deploy httpd
- hosts: ansible2.example.com
- vars_files:
- - packages.yml
- vars:
- supported_distros:
- - CentOS
- - RedHat
- tasks:
- - name: setting up httpd service
- block:
- - name: Install web packages
- yum:
- name: "{{ item }}"
- state: present
- loop: "{{ webpackages }}"
- become: yes
- - name: enable and start httpd
- service:
- name: httpd
- enabled: true
- state: started
- become: yes
- - name: allow http and https
- firewalld:
- service: "{{ item }}"
- permanent: true
- immediate: true
- state: enabled
- loop:
- - http
- - https
- become: yes
- when: ansible_facts['distribution'] in supported_distros and ansible_facts['distribution_version'] >= "8"
- - debug:
- msg: echo "Host {{ ansible_facts['hostname'] }} does not meet minimal requirements"
- when: ansible_facts['distribution'] not in supported_distros or ansible_facts['distribution_version'] < "8"
- - name: create index.html in local /tmp
- hosts: localhost
- tasks:
- - name: create Index.html in local /tmp
- copy:
- content: "Welcome to my webserver"
- dest: /tmp/index.html
- owner: root
- group: root
- - name: deploy index.html
- hosts: ansible2.example.com
- tasks:
- - name: copy index.html to /var/www/html
- copy:
- src: /tmp/index.html
- dest: /var/www/html
- owner: root
- group: root
- mode: "0644"
- register: command_result
- notify:
- - restart_web
- - name: debugging
- debug:
- var: command_result
- - debug:
- msg: echo "Failed copying index.html to {{ ansible_facts['hostname'] }}"
- when: not command_result.changed
- handlers:
- - name: restart_web
- service:
- name: httpd
- state: restarted
- [ansible@control lesson8]$ cat packages.yml
- webpackages:
- - httpd
- - mod_ssl
Add Comment
Please, Sign In to add comment