Friday, March 15, 2019

Ansible

Ansible installation

go to the root and check:

sudo yum repolist
sudo yum install -y ansible

https://docs.ansible.com/ansible/latest/user_guide/vault.html

noble ALL=(ALL) NOPASSWD:ALL

ssh copy-id noble@10.142.0.6


permission for
ssh folder - 700
authorized_keys-- 600
sudoers --- 755



ansible node -m copy -a 'src=/etc/ansible/noble6ansi.txt dest=/home/noble1'

ansible node -m file -a  'dest=/home/noble1/noble6ansi.txt mode=777'



After anisble is installed

under root go to /etc/ansible
and change the ownership from root to the noble(user):
chown noble:noble /etc/ansible


After, putting server and nodes in etc/hosts file, check if ansible reaches out the server and hosts

ansible server -m ping
ansible node -m ping




This is the default ansible 'hosts' file.Connected, host fingerprint: ssh-rsa 0 4C:7C:0B:94:DD:30:37:3D:CE:E9:EB:D4:21:D4:FA:AE:75:27:AA:22:D1:F1:95:4B:C1:56:9C:49:59:F1:F5:4ELast login: Fri Mar 15 05:35:17 2019 from 173.194.102.16[kafleashok1@devopstrial ~]$ su noble[noble@devopstrial kafleashok1]$ cdHello this is a test for ansible[noble@devopstrial ~]$ ssh noble@devopstrialLast login: Fri Mar 15 15:28:44 2019[noble@devopstrial ~]$ cd /etc/ansible[noble@devopstrial ansible]$ Connected, host fingerprint: ssh-rsa 0 4C:7C:0B:94:DD:30:37:3D:CE:E9:EB:D4:21:D4:FA:AE:75:27:AA:22:D1:F1:95:4B:C1:56:9C:49:59:F1:F5:4ELast login: Fri Mar 15 15:28:06 2019 from 173.194.102.9[kafleashok1@devopstrial ~]$ su noble[noble@devopstrial kafleashok1]$ ls -ltrls: cannot open directory .: Permission denied[noble@devopstrial kafleashok1]$ cd[noble@devopstrial ~]$ ls -ltrtotal 0-rw-rw-r--. 1 noble noble 0 Mar 15 02:12 authorized_keys[noble@devopstrial ~]$ vi authorized_keys [noble@devopstrial ~]$ rm authorized_keys [noble@devopstrial ~]$ ls -ltrtotal 0[noble@devopstrial ~]$ cd /etc/hostsbash: cd: /etc/hosts: Not a directory[noble@devopstrial ~]$ cd /etc/ansible[noble@devopstrial ansible]$ ls -ltrtotal 24drwxr-xr-x. 2 noble noble 6 Feb 21 23:04 roles-rw-r--r--. 1 noble noble 1016 Feb 21 23:04 hosts-rw-r--r--. 1 noble noble 20277 Feb 21 23:04 ansible.cfg[noble@devopstrial ansible]$ vi hosts[noble@devopstrial ansible]$ ansible server -m ping10.142.0.6 | SUCCESS => { "changed": false, "ping": "pong"}[noble@devopstrial ansible]$ ansible -m server pingHello this is a test for ansible [WARNING]: Could not match supplied host pattern, ignoring: ping [WARNING]: No hosts matched, nothing to do


noble@devopstrial ansible]$ ansible node -m ping10.142.0.2 | SUCCESS => { "changed": false, "ping": "pong"}[noble@devopstrial ansible]$ touch noble1.txt[noble@devopstrial ansible]$ vi noble1.txt [noble@devopstrial ansible]$ ansible node -m copy -a 'src=/etc/ansible/noble1.txt dest =/home/noble'ERROR! this task 'copy' has extra params, which is only allowed in the following modules: shell, win_shell, include_vars, add_host, raw, include_role, meta, set_fact, include, import_tasks, script, import_role, include_tasks, group_by, command, win_command[noble@devopstrial ansible]$ ansible node -m copy -a 'src=/etc/ansible/noble1.txt dest=/home/noble'10.142.0.2 | CHANGED => { "changed": true, "checksum": "73b0c1ba7659a1f6a366d3bc6a29f027c429136c", "dest": "/home/noble/noble1.txt", "gid": 1003, "group": "noble", "md5sum": "5d756118278361c3aa9d2aa1396631cc", "mode": "0664", "owner": "noble", "secontext": "unconfined_u:object_r:user_home_t:s0", "size": 34, "src": "/home/noble/.ansible/tmp/ansible-tmp-1552666208.98-214978604854310/source", "state": "file", "uid": 1002}[noble@devopstrial ansible]$ ssh noble@instance_1ssh: Could not resolve hostname instance_1: Name or service not known[noble@devopstrial ansible]$ ssh noble@10.142.0.2Last login: Fri Mar 15 16:10:10 2019 from devopstrial.c.adept-tangent-207418.internal[noble@instance-1 ~]$ ls -ltrtotal 4-rw-rw-r--. 1 noble noble 34 Mar 15 16:10 noble1.txt[noble@instance-1 ~]$ vi noble1.txt[noble@instance-1 ~]$ exit


logoutConnection to 10.142.0.2 closed.[noble@devopstrial ansible]$ ansible -m copy -a 'src=/etc/ansible/noble1.txt mode=777'Usage: ansible <host-pattern> [options]Define and run a single task 'playbook' against a set of hostsOptions: -a MODULE_ARGS, --args=MODULE_ARGS module arguments --ask-vault-pass ask for vault password -B SECONDS, --background=SECONDS run asynchronously, failing after X seconds (default=N/A) -C, --check don't make any changes; instead, try to predict some of the changes that may occur -D, --diff when changing (small) files and templates, show the differences in those files; works great with --check -e EXTRA_VARS, --extra-vars=EXTRA_VARS set additional variables as key=value or YAML/JSON, if filename prepend with @ -f FORKS, --forks=FORKS specify number of parallel processes to use (default=5) -h, --help show this help message and exit -i INVENTORY, --inventory=INVENTORY, --inventory-file=INVENTORY specify inventory host path or comma separated host list. --inventory-file is deprecated -l SUBSET, --limit=SUBSET further limit selected hosts to an additional pattern --list-hosts outputs a list of matching hosts; does not execute anything else -m MODULE_NAME, --module-name=MODULE_NAME module name to execute (default=command) -M MODULE_PATH, --module-path=MODULE_PATH prepend colon-separated path(s) to module library (default=[u'/home/noble/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']) -o, --one-line condense output --playbook-dir=BASEDIR
-P POLL_INTERVAL, --poll=POLL_INTERVAL set the poll interval if using -B (default=15) --syntax-check perform a syntax check on the playbook, but do not execute it -t TREE, --tree=TREE log output to this directory --vault-id=VAULT_IDS the vault identity to use --vault-password-file=VAULT_PASSWORD_FILES vault password file -v, --verbose verbose mode (-vvv for more, -vvvv to enable connection debugging) --version show program's version number and exit Connection Options: control as whom and how to connect to hosts -k, --ask-pass ask for connection password --private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE use this file to authenticate the connection -u REMOTE_USER, --user=REMOTE_USER connect as this user (default=None) -c CONNECTION, --connection=CONNECTION connection type to use (default=smart) -T TIMEOUT, --timeout=TIMEOUT override the connection timeout in seconds (default=10) --ssh-common-args=SSH_COMMON_ARGS specify common arguments to pass to sftp/scp/ssh (e.g. ProxyCommand) --sftp-extra-args=SFTP_EXTRA_ARGS specify extra arguments to pass to sftp only (e.g. -f, -l) --scp-extra-args=SCP_EXTRA_ARGS specify extra arguments to pass to scp only (e.g. -l) --ssh-extra-args=SSH_EXTRA_ARGS specify extra arguments to pass to ssh only (e.g. -R) Privilege Escalation Options:
control how and which user you become as on target hosts -s, --sudo run operations with sudo (nopasswd) (deprecated, use become) -U SUDO_USER, --sudo-user=SUDO_USER desired sudo user (default=root) (deprecated, use become) -S, --su run operations with su (deprecated, use become) -R SU_USER, --su-user=SU_USER run operations with su as this user (default=None) (deprecated, use become) -b, --become run operations with become (does not imply password prompting) --become-method=BECOME_METHOD privilege escalation method to use (default=sudo), valid choices: [ sudo | su | pbrun | pfexec | doas | dzdo | ksu | runas | pmrun | enable | machinectl ] --become-user=BECOME_USER run operations as this user (default=root) --ask-sudo-pass ask for sudo password (deprecated, use become) --ask-su-pass ask for su password (deprecated, use become) -K, --ask-become-pass ask for privilege escalation passwordSome modules do not make sense in Ad-Hoc (include, meta, etc)ERROR! Missing target hosts[noble@devopstrial ansible]$ ansible -m file -a 'dest=/home/noble1.txt mode=777' Usage: ansible <host-pattern> [options]Define and run a single task 'playbook' against a set of hostsOptions: -a MODULE_ARGS, --args=MODULE_ARGS module arguments --ask-vault-pass ask for vault password -B SECONDS, --background=SECONDS run asynchronously, failing after X seconds (default=N/A) -C, --check don't make any changes; instead, try to predict some of the changes that may occur
-D, --diff when changing (small) files and templates, show the differences in those files; works great with --check -e EXTRA_VARS, --extra-vars=EXTRA_VARS set additional variables as key=value or YAML/JSON, if filename prepend with @ -f FORKS, --forks=FORKS specify number of parallel processes to use (default=5) -h, --help show this help message and exit -i INVENTORY, --inventory=INVENTORY, --inventory-file=INVENTORY specify inventory host path or comma separated host list. --inventory-file is deprecated -l SUBSET, --limit=SUBSET further limit selected hosts to an additional pattern --list-hosts outputs a list of matching hosts; does not execute anything else -m MODULE_NAME, --module-name=MODULE_NAME module name to execute (default=command) -M MODULE_PATH, --module-path=MODULE_PATH prepend colon-separated path(s) to module library (default=[u'/home/noble/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']) -o, --one-line condense output --playbook-dir=BASEDIR Since this tool does not use playbooks, use this as a subsitute playbook directory.This sets the relative path for many features including roles/ group_vars/ etc.

-P POLL_INTERVAL, --poll=POLL_INTERVAL set the poll interval if using -B (default=15) --syntax-check perform a syntax check on the playbook, but do not execute it -t TREE, --tree=TREE log output to this directory --vault-id=VAULT_IDS the vault identity to use --vault-password-file=VAULT_PASSWORD_FILES vault password file -v, --verbose verbose mode (-vvv for more, -vvvv to enable connection debugging) --version show program's version number and exit Connection Options: control as whom and how to connect to hosts -k, --ask-pass ask for connection password --private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE use this file to authenticate the connection -u REMOTE_USER, --user=REMOTE_USER connect as this user (default=None) -c CONNECTION, --connection=CONNECTION connection type to use (default=smart) -T TIMEOUT, --timeout=TIMEOUT override the connection timeout in seconds (default=10) --ssh-common-args=SSH_COMMON_ARGS specify common arguments to pass to sftp/scp/ssh (e.g. ProxyCommand) --sftp-extra-args=SFTP_EXTRA_ARGS specify extra arguments to pass to sftp only (e.g. -f, -l) --scp-extra-args=SCP_EXTRA_ARGS specify extra arguments to pass to scp only (e.g. -l) --ssh-extra-args=SSH_EXTRA_ARGS specify extra arguments to pass to ssh only (e.g. -R) Privilege Escalation Options: control how and which user you become as on target hosts -s, --sudo run operations with sudo (nopasswd) (deprecated, use become)



-U SUDO_USER, --sudo-user=SUDO_USER desired sudo user (default=root) (deprecated, use become) -S, --su run operations with su (deprecated, use become) -R SU_USER, --su-user=SU_USER run operations with su as this user (default=None) (deprecated, use become) -b, --become run operations with become (does not imply password prompting) --become-method=BECOME_METHOD privilege escalation method to use (default=sudo), valid choices: [ sudo | su | pbrun | pfexec | doas | dzdo | ksu | runas | pmrun | enable | machinectl ] --become-user=BECOME_USER run operations as this user (default=root) --ask-sudo-pass ask for sudo password (deprecated, use become) --ask-su-pass ask for su password (deprecated, use become) -K, --ask-become-pass ask for privilege escalation passwordSome modules do not make sense in Ad-Hoc (include, meta, etc)ERROR! Missing target hosts[noble@devopstrial ansible]$ ansible node -m file -a 'dest=/home/noble1.txt mode=777'10.142.0.2 | FAILED! => { "changed": false, "msg": "file (/home/noble1.txt) is absent, cannot continue", "path": "/home/noble1.txt", "state": "absent"}[noble@devopstrial ansible]$ ansible node -m file -a 'dest=/home/noble/noble1.txt mode=777'10.142.0.2 | CHANGED => { "changed": true, "gid": 1003, "group": "noble", "mode": "0777", "owner": "noble", "path": "/home/noble/noble1.txt", "secontext": "unconfined_u:object_r:user_home_t:s0", "size": 34,
"state": "file", "uid": 1002}[noble@devopstrial ansible]$ ssh noble@10.142.0.2Last login: Fri Mar 15 16:13:33 2019 from devopstrial.c.adept-tangent-207418.internal[noble@instance-1 ~]$ ls -ltrtotal 4-rwxrwxrwx. 1 noble noble 34 Mar 15 16:11 noble1.txt[noble@instance-1 ~]$




Sunday, February 17, 2019

As Good as Mom and Dad (February 17 2019

                                                    As Good as MOM and DAD ?

        Have you ever wondered if you can make as far as your mom and dad did ? If not, stop  whatever you are doing, sit back, relax and try to contemplate your parent's journey for a moment. Remember how they nurture you up merely fulfilling or trying to fulfill all your puerile wishes and those of your siblings if you had any. Now, if you have already graduated or are about to graduate, this is the age your parents probably got married or some of ours' already had us. Isn't it really scary to put ourselves in their situation ? I mean, till date you still  get perplexed if you should swear the same socks as yesterday because they don't seem to smell yet or go with another pair and your parents at this stage probably had your naming ceremony done.Strange and scary but true !!

      I cannot vouch for everyone and i am not entitled to do so. But if there is something i can do, then it is to reflect on my own journey and  relate that with that of my father and mother. My father is always calm and composed and loyal to his rituals. He is  a man of honor ; a government servant constantly working for more than twenty years, first to feed his family and now it  has also become part of his ritual.On other hand, my mother is a risk-taker and an independent woman .She is a complete contrast of calmness and composure that i mentioned regarding my father. Finally, my younger brother and me, we like the George R.R. Martin's book, are the song of ice and fire.





The next five years of your life will determine if you will ever  reach to the benchmark set by them or not. So, ladies and gentlemen it's time to gear up.
TBC

Monday, October 15, 2018

JenkinsCertification-Class 1(Jenkins Installation)

* https://console.cloud.google.com/networking/firewalls/details/default-allow-http?q=search&project=probable-cove-183916

* sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

*sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

* sudo yum install jenkins

*sudo yum install wget

*Sudo systemctl start jenkins

sudo visudo

sudo vi /etc/ssh/sshd_config

sudo service sshd start

sudo service sshd restart


1 systemctl enable jenkins 2 systemctl start jenkins 3 systemctl status jenkins 4 java -version 5 yum install java 6 java -version 7 systemctl start jenkins 8 ps -ef jenkins 9 ps -ef | grep jenkins 10 cd /usr/lib/jenkins/ 11 ls -ltr 12 cd .. 13 cd usr 14 cd /usr 15 ps -ef | grep jenkins 16 cd /etc/default 17 ls -ltr 18 less instance_configs.cfg 19 cd /etc 20 ls -ltr 21 cd sysconfig 22 ls -ltr 23 less jenkins 24 pwd 25 pwd 26 ls -ltr 27 tail -f jenkins.log

Friday, October 5, 2018

Introvert or Extrovert

When you laugh a little loud, you are ill-mannered and when you laugh a little less, you are shy. Our social structures have made it a little complex for our Generation-Y aka millennial to grasp and apply these norms.Especially in context of Nepal, it is even more difficult to grow as a child; Because not only your parents, but also your neighbors, relatives and even friend's parents are watchdogs of your mannerism.Besides, there is this whole  decade long phenomenon and worshiper of discipline called school. The sad part, no child can escape it.I mean who as a scholar haven't heard this, " Does your parents teach this?" at school and "This is what you learn at school ?" at home .I believe every single of us.First of all please make sure who teaches what. This will make the life of a child more easier.Here, i am not trying to put blame on either of them. I couldn't have been grown up better and neither could have been educated better.So, both my parents and school have grabbed A+ on their transcripts.If allowed, i would give some partial credit to my neighbors and relatives as well.However, my problem is with the overall system and culture.

I cannot draw a conclusion representing my age group but i am trying to put my own perspective and experience.



Tuesday, September 18, 2018

4. Median of Two Sorted Arrays(Leetcode) Accepted solution

class Solution:
def findMedianSortedArrays(self,l1,l2):
sorted_new_list = l1 + l2
sorted_new_list.sort()
val = len(sorted_new_list)
if (val % 2 != 0):
return float(sorted_new_list[val //2])
else:
num1 = sorted_new_list[val//2 -1]
num2 = sorted_new_list [val//2]
return (num1 +num2 )/2
a = Solution()
print(a.findMedianSortedArrays([1,2,3,4,5] ,[6,7,8,9]))