You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Excercise 3 - Write a ansible module using Adhoc commands to create a user and add him into sudoers and using regular user only run "Excercise 3" all adhoc commands to remote machine.
- name: Create a user and add it to the group
hosts: web
tasks:
- name: Create a group
group: name=deploy state=present
- name: Create a user and add to group
user: name=deploy group=deploy
- name: Setup a web server
hosts: web
tasks:
- name: Install Apache
yum: name=httpd
- name: Start Apache server
service: name=httpd state=started
- name: Write contents to a file on webserver
hosts: web
tasks:
- name: Create a directory
file: path=/var/www/html state=directory
- name: Create a file
file: dest=/var/www/html/index.html mode=600 state=touch
- name: Write contents to the file
lineinfile: dest=/var/www/html/index.html line='<html> <h1> Welcome to HP Ansible class </h1> </html>'
- name: Reboot the Apache server
hosts: web
tasks:
- name: Restart the httpd server
reboot:
---
- name: Install git and wget packages
hosts: web
tasks:
- name: Install git, wget packages
yum: name=git,wget state=present
- name: Clone the repo
hosts: web
tasks:
- name: Create a temp directory to host repo
file: path=/tmp/test state=directory
- name: Clone the repo using url
git: repo=https://github.com/scmgalaxy/ansible-role-template clone=yes dest=/tmp/test
playbook exercise:
name: create group and user
hosts: localhost
tasks:
group: name=deploy1 state=present
user: name=deploy-user1 group=deploy1 state=present
name: This sets up git
hosts: localhost
tasks:
yum: name=git state=present
yum: name=wget state=present
git: repo=https://github.com/scmgalaxy/ansible-role-template dest=/src/ansible-examples separate_git_dir=/src/ansible-examples.gitstate=present
name: This sets up an httpd webserver
hosts: localhost
tasks:
yum: name=httpd
service: name=httpd state=started
name: create file and copy
hosts: localhost
tasks:
file: dest=/opt/index.html mode=600 state=touch
copy: dest=/opt/index.html content='
Welcome to HP Ansible class
'copy: src=/opt/index.html dest=/var/www/html/index.html