I am experimenting with Ansible by reading the great Ansible Up and Running book by Lorin Hochstein.
On a Ubuntu 16.04 machine with Ansible, I am trying now to run the web-tls playbook.
As example, I created a web-notls.yml file and I did put in the playbook directory:
- name: Configure webserver with nginx
hosts: webservers
sudo: True
tasks:
- name: install nginx
apt: name=nginx update_cache=yes
- name: copy nginx config file
copy: src=files/nginx.conf dest=/etc/nginx/sites-available/default
- name: enable configuration
file: >
dest=/etc/nginx/sites-enabled/default
src=/etc/nginx/sites-available/default
state=link
- name: copy index.html
template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html
mode=0644
- name: restart nginx
service: name=nginx state=restarted
I also specified a nginx.conffile and I did put it in playbooks/files/nginx.conf directory:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
}
I also created hosts file to access the Vagrant machine easily and a web custom homepage to see a message after accessing the web page.
I modified the Vagrantfile to contain this code:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 443, host: 8443
end
After this change, the port 8080 on my local machine should be forwarded t othe port 80 of the Vagrant machine, and the port 8443 on my local machine should be forwarded to ort 443 on the vagrant machine: 8080 Port forwarding Architecture When trying to run the playbook by:
$ ansible-playbook web-notls.yml
the ouput is:
luigi@luigi-H87-HD3:~/playbooks$ ansible-playbook web-notls.yml
[DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be a list of
hosts, a directory or a list of paths , use [defaults] inventory=/path/to/file|dir instead. This
feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method
is 'sudo' (default). This feature will be removed in version 2.6. Deprecation warnings can be
disabled by setting deprecation_warnings=False in ansible.cfg.
PLAY [Configure webserver with nginx] ***************************************************************
TASK [Gathering Facts] ******************************************************************************
ok: [testserver]
TASK [install nginx] ********************************************************************************
ok: [testserver]
TASK [copy nginx config file] ***********************************************************************
ok: [testserver]
TASK [enable configuration] *************************************************************************
ok: [testserver]
TASK [copy index.html] ******************************************************************************
ok: [testserver]
TASK [restart nginx] ********************************************************************************
changed: [testserver]
PLAY RECAP ******************************************************************************************
testserver : ok=6 changed=1 unreachable=0 failed=0
It seems like no errors so far. I am now trying to open localhost:8080 address by browser on my local machine (I also tried to do a vagrant ssh and try curl localhost:8080 with no success) but I receive no results. What am I doing wrong ?
Thank you in advance!