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.
Write a Ansible Adhoc Commands to create a group called “deploy”
ansible all -i 10.76.137.151, -m group -a "name=deploy state=present" -u tester -K -b -k
[root@localhost ~]# ansible all -i 10.76.137.151, -m group -a "name=deploy state=present" -u tester -K -b -k
SSH password:
BECOME password[defaults to SSH password]:
10.76.137.151 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"gid": 1001,
"name": "deploy",
"state": "present",
"system": false
}
Write a Ansible Adhoc Commands to create a user called “deploy-user” which is part of group called “deploy” and
with /bin/bash shell.
#ansible all -i 10.76.137.151, -m user -a "name=deploy group=deploy" -u tester -K -b -k
[root@localhost ~]# id deploy
uid=1001(deploy) gid=1001(deploy) groups=1001(deploy)
[root@localhost ~]# id deploy-user
uid=1002(deploy-user) gid=1001(deploy) groups=1001(deploy)
Write a Ansble Adhoc commands install package named “httpd” in RHEL/centos.
ansible all -i 10.76.137.151, -m yum -a "name=httpd state=present" -u tester -K -b -k
After the command output on ARS is as:
[root@localhost ~]# rpm -qa | grep -i http
httpd-tools-2.4.6-89.el7.centos.x86_64
httpd-2.4.6-89.el7.centos.x86_64
Write a Ansible Adhoc commands to start and enable the service named “httpd”
#ansible all -i 10.76.137.151, -m service -a "name=httpd state=started" -u tester -K -b -k
successful message
Write a Ansible commands to create a file called “index.html” in /var/www/html with some dummy html contents.
ansible all -i 10.76.137.151, -m file -a "path=/var/www/html state=directory" -u tester -K -b -k
ansible all -i 10.76.137.151, -m file -a "dest=/var/www/html/index.html mode=600 state=touch" -u tester -K -b -k
ansible all -i 10.76.137.151, -m lineinfile -a "dest=/var/www/html/index.html line=' # Welcome to HP Ansible class '" -u tester -K -b -k
- 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