##############Ansible ###############
play book is composed of 1 or more plays in a list
The goal of a play is to map a group of hosts to some well defined roles, represented by things ansible calls tasks. At a basic level, a task is nothing more than a call to an ansible module, which you should have learned about in earlier chapters.
---
- hosts: webservers
remote_user: root
tasks:
- name: create the new user
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running
service: name=httpd state=started
handlers:
- name: restart apache
service: name=httpd state=restarted
ansible 192.168.140.20 -a "/usr/bin/yum install libselinux-python"
pip install passlib
python -c "from passlib.hash import sha512_crypt; print sha512_crypt.encrypt('nepal12')"
$6$rounds=100000$KYpBC3u43XAxBJNg$7Gh04HYw3wySag8uYqeRghh0L.MtLhVTzNMEe5vr71CFWLSarvHGwrV4I.vStCXzwdPYScZFOHrfrxvl9wzMK1
copy and paste the result like below
ansible all -m user -a 'name=foo password=$6$rounds=100000$40KA9Y5UUFMh/6xC$/rUKR9Qqu7S56nQm9bV91izUA8ExDIb5rxg73QYeyHO.uGiN/9tgfgfdycsj74F36Lz6E1ZvcZf.Bz4wzwxQk0'
Play book for creating user , group with id 777 , add new user to group , copy file from local ansible server to remote client , add new user to sudoers file , install nrpe in client
---
- name: Hello World!
gather_facts: False
hosts: all
vars:
password: '$6$rounds=100000$3b69WiNTWemboVhu$IGTjv.FvMEDVzXRHEey9ddmuxKhAFL8BBL8unvCos9fcTPQkxkIEEHs1QWraTejPai5ytcq7Hs3Y3ZJ3qmRHv.'
user: root
tasks:
- action: group name=demogroup1 gid=777 state=present
- action: user name=nplinkuser1 password={{password}}
- action: user name=nplinkuser1 groups=demogroup1 append=yes
- copy: src=/asia dest=/
- lineinfile: "dest=/etc/sudoers state=present regexp='^nplinkuser1' line='nplinkuser1 ALL=(ALL) ALL'"
- yum: name=nrpe state=latest
play book is composed of 1 or more plays in a list
The goal of a play is to map a group of hosts to some well defined roles, represented by things ansible calls tasks. At a basic level, a task is nothing more than a call to an ansible module, which you should have learned about in earlier chapters.
---
- hosts: webservers
remote_user: root
tasks:
- name: create the new user
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running
service: name=httpd state=started
handlers:
- name: restart apache
service: name=httpd state=restarted
ansible 192.168.140.20 -a "/usr/bin/yum install libselinux-python"
pip install passlib
python -c "from passlib.hash import sha512_crypt; print sha512_crypt.encrypt('nepal12')"
$6$rounds=100000$KYpBC3u43XAxBJNg$7Gh04HYw3wySag8uYqeRghh0L.MtLhVTzNMEe5vr71CFWLSarvHGwrV4I.vStCXzwdPYScZFOHrfrxvl9wzMK1
copy and paste the result like below
ansible all -m user -a 'name=foo password=$6$rounds=100000$40KA9Y5UUFMh/6xC$/rUKR9Qqu7S56nQm9bV91izUA8ExDIb5rxg73QYeyHO.uGiN/9tgfgfdycsj74F36Lz6E1ZvcZf.Bz4wzwxQk0'
Play book for creating user , group with id 777 , add new user to group , copy file from local ansible server to remote client , add new user to sudoers file , install nrpe in client
---
- name: Hello World!
gather_facts: False
hosts: all
vars:
password: '$6$rounds=100000$3b69WiNTWemboVhu$IGTjv.FvMEDVzXRHEey9ddmuxKhAFL8BBL8unvCos9fcTPQkxkIEEHs1QWraTejPai5ytcq7Hs3Y3ZJ3qmRHv.'
user: root
tasks:
- action: group name=demogroup1 gid=777 state=present
- action: user name=nplinkuser1 password={{password}}
- action: user name=nplinkuser1 groups=demogroup1 append=yes
- copy: src=/asia dest=/
- lineinfile: "dest=/etc/sudoers state=present regexp='^nplinkuser1' line='nplinkuser1 ALL=(ALL) ALL'"
- yum: name=nrpe state=latest
No comments:
Post a Comment