Adding vars to the play

Variables can be defines in many locations, and we can get them from the facts gathering stage as well.

lets add some content to the nginx servers, create a file called index.html.tpl with the content:


<!DOCTYPE html>
<html>
<head>
<title>Welcome to ubuntu-1</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to ubuntu-1</h1>
</body>
</html>

and run the playbook again:


yonit@ansible_server:~/ansible$ ansible-playbook nginx_install.yml

PLAY [virtualhosts] ******************************************************************************

TASK [Gathering Facts] *************************************************************************
ok: [ubuntu-1]
ok: [ubuntu-2]

TASK [install nginx] ***************************************************************************
ok: [ubuntu-1]
ok: [ubuntu-2]

TASK [Setup nginx conf] ************************************************************************
ok: [ubuntu-1]
ok: [ubuntu-2]

TASK [add index.html file] *********************************************************************
changed: [ubuntu-2]
changed: [ubuntu-1]

PLAY RECAP ***************************************************************************************
ubuntu-1                   : ok=4    changed=1    unreachable=0    failed=0
ubuntu-2                   : ok=4    changed=1    unreachable=0    failed=0

now lets see it:


yonit@ansible_server:~/ansible$ curl http://ubuntu-2/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to ubuntu-1</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to ubuntu-1</h1>
</body>
</html>