April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Ansibile yaml file

autocmd FileType yank setlocal ai ts=2 sw=2 et vim set cursorcolumn color

ansible trail

##### Steps for deployment of Ansible on CentOS 7

##### Dependency Tasks

### Install EPEL sudo yum install epel-release

### Install pending updates sudo yum -y update

##### Install Ansible

### Install Ansible sudo yum -y install ansible

### Verify the Version ansible –version

[db] node1.rmohan.com [app] node2.rmohan.com [db] node3.rmohan.com

ansible all –list-hosts ansible db […]

Ansible-palybooks

Ansible-palybooks

root@controller:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/root/.ssh/id_rsa. Your public key has been saved in /home/root/.ssh/id_rsa.pub. The key fingerprint is: 33:b8:4d:8f:95:bc:ed:1a:12:f3:6c:09:9f:52:23:d0 root@controller The key’s randomart image is: +–[ RSA […]

Managing files in ansible

Managing files in ansible

[root@controller ~]$ ansible localhost –list-hosts

hosts (1): localhost ——————————————- [root@controller ~]$ vim file.yaml — – name: creating a file hosts: localhost tasks: – file: path: /home/root/sample state: touch owner: root group: root mode: 0755 … ——————————————- [root@controller ~]$ ansible-playbook –syntax-check file.yaml

playbook: file.yaml

—————————————- [root@controller ~]$ ansible-playbook -C file.yaml

PLAY [creating […]

ansible vault

root@controller ~]# ansible-vault create mohan.yml Vault password:

[root@controller ~]# cat mohan.yml $ANSIBLE_VAULT;1.1;AES256 38623235633039636166356162393064363936303461306536386237663032383932656164633131 6132633132376266313863366164396535386539666562310a306562383834343431633536353332 63303935623030393261373030343366323361653238306531356434333538613236303738653730 3935313536396361640a343836366434613638316538333165366161306166396564353635383831 30636536366462646362373432396234383432376437633764616239393938366137

[root@controller ~]# ansible-vault view mohan.yml Vault password: hai how are you

[root@controller ~]# ansible-vault edit mohan.yml Vault password:

[root@controller ~]# ansible-vault rekey mohan.yml Vault password: New Vault password: Confirm New Vault password: Rekey successful

[root@controller ~]# ansible-playbook mohan.yml […]

JINJA2 templates in ansible

JINJA2 templates in ansible

[root@workstation ~]# ansible -m ping all 192.168.1.23 | SUCCESS => { “changed”: false, “ping”: “pong” } 192.168.1.22 | SUCCESS => { “changed”: false, “ping”: “pong” }

========================================= [root@workstation ~]# vim motd.j2 this is {{ ansible_hostname }}. today’s date is {{ ansible_date_time.date }} you can ask {{ system_owner }} for access ========================================== […]

Creating role in ansible

Creating a basic role for displaying message of the day

[root@workstation ~]# vim /etc/ansible/roles/motd/main.yml — – name: use motd role playbook hosts: all

roles: – motd

[root@workstation ~]# vim /etc/ansible/roles/motd/defaults/main.yml — system_owner: rmohan [root@workstation ~]# vim /etc/ansible/roles/motd/tasks/main.yml — – name: deliver motd file template: src: templates/motd.j2 dest: /etc/motd owner: root group: root mode: 777 [root@workstation […]

HANDLERS & register in ansible

HANDLERS & register in ansible

[root@workstation ~]# vim register.yaml — – name: checking the register module functionality hosts: localhost tasks: – name: command: ps register: output – debug: msg=”{{ output.stdout }}” ==================================================== [root@workstation ~]# ansible-playbook –syntax-check register.yaml

playbook: register.yaml

[root@workstation ~]# ansible-playbook register.yaml

PLAY [checking the register module functionality] ******************************

TASK [setup] ******************************************************************* ok: [localhost]

[…]

Tags in ansible

Tags in ansible

[root@workstation ~]# vim tags.yaml — – name: installing postfix and stopping from starting service hosts: localhost tasks: – name: installing postfix package yum: name=postfix state=latest tags: packageonly – name: starting service service: name=postfix state=started [root@workstation ~]# ansible-playbook –syntax-check tags.yaml

playbook: tags.yaml [root@workstation ~]# ansible-playbook -C tags.yaml

PLAY [installing postfix and stopping from […]

Creating role in ansible

Creating role in ansible

Creating a basic role for displaying message of the day

[root@workstation ~]# vim /etc/ansible/roles/motd/main.yml — – name: use motd role playbook hosts: all

roles: – motd

[root@workstation ~]# vim /etc/ansible/roles/motd/defaults/main.yml — system_owner: rmohan [root@workstation ~]# vim /etc/ansible/roles/motd/tasks/main.yml — – name: deliver motd file template: src: templates/motd.j2 dest: /etc/motd owner: root group: […]