|
42 | 42 | * Go to security Credentials download security access token file
|
43 | 43 | * run command ``` aws configure ```
|
44 | 44 | * enter your credentials from file
|
45 |
| - * |
| 45 | + * |
| 46 | + ----- |
| 47 | + |
| 48 | + # ansible |
| 49 | + |
| 50 | + * ansible --version # shows the version of ansible |
| 51 | + * ansible all -m ping # used to run command on all ip in hosts file |
| 52 | + * ssh-copy-id ip-address # used to send the ssh of your system to other systems you want to get access to |
| 53 | + * to ssh-copy you will need the password of all those os |
| 54 | + * always write ansible playbooks in a directory |
| 55 | + * Syntax |
| 56 | + ``` |
| 57 | + --- |
| 58 | + - hosts:192.168.10.41 # play1 |
| 59 | + tasks: |
| 60 | + - name: running database |
| 61 | + command: date |
| 62 | +
|
| 63 | + - hosts:192.168.10.72 # play2 |
| 64 | + tasks: |
| 65 | + - name: running database |
| 66 | + command: cal |
| 67 | + ``` |
| 68 | + * multi-play - > when to run different command on different os |
| 69 | + * always make a sample playbook of yml |
| 70 | + |
| 71 | + ``` |
| 72 | + --- |
| 73 | + - hosts: all # all is used when need to work on all ip in hosts file |
| 74 | + vars: |
| 75 | + x: date |
| 76 | + tasks: |
| 77 | + - name: running |
| 78 | + command: "{{ x }}" |
| 79 | + register: variable-name # register store the output of above command inside it |
| 80 | +
|
| 81 | + - name: to print data of var |
| 82 | + debug: var=out # printing the data stored in variable above |
| 83 | +
|
| 84 | + - name: to print date command output clearly |
| 85 | + debug: var=out.stdout # by default out is a json format and thus we can find easily using dictionary pattern |
| 86 | +
|
| 87 | + - name: to print date command output with some message |
| 88 | + debug: msg="hello my output is {{ out.stdout }} " |
| 89 | +
|
| 90 | + - name: to store output of command in a file |
| 91 | + copy: content=" {{ variable }}" dest=output.txt |
| 92 | + ``` |
| 93 | + * ansible-playbook playbook-name.yml -v # shows the output of command |
| 94 | + * ansible-playbook playbook-name.yml -e x=command , used to change variable value for x written in ansible playbook |
| 95 | + * to check ansible playbook |
| 96 | + ```ansible-playbook --syntax-check play-book name``` |
| 97 | + |
| 98 | + * importing variables from a file |
| 99 | + |
| 100 | + * hosts file is known as inventory |
| 101 | + * to run different inventory file |
| 102 | + ``` |
| 103 | + ansible-playbook playbook-name.yml -i /etc/hosts1 # hosts1 is inventory name |
| 104 | +
|
| 105 | + * to change default settings of ansible |
| 106 | + ``` |
| 107 | + /etc/ansible/ansible.cfg |
| 108 | + ``` |
| 109 | + * By default ansible is service less, it reads the conf file from present working directory initially |
| 110 | + * ```ssh ip -t "command to run "``` shows output on your own system that is run on other system |
| 111 | + * Inventory Variable |
| 112 | + * in inventory file or hosts file |
| 113 | + ``` |
| 114 | + [group-name:vars] |
| 115 | + x=date |
| 116 | + ``` |
| 117 | + * to make different group have same variable make children or group in hosts file |
| 118 | + ``` |
| 119 | + [ok:children] |
| 120 | + a |
| 121 | + b |
| 122 | + ``` |
| 123 | + * to define group variables |
| 124 | + ``` |
| 125 | + [ok:vars] |
| 126 | + x=date |
| 127 | + ``` |
| 128 | + * to apply vars for all ips , make a directory named vars |
| 129 | +
|
| 130 | + * for more info |
| 131 | + ``` |
| 132 | + slashdevops.blogspot.com |
| 133 | + ``` |
| 134 | + * search for ansible |
| 135 | +
|
| 136 | +## Ansible facts |
| 137 | + * to know different variables existing on self system |
| 138 | + ``` |
| 139 | + ansible localhost -m setup |
| 140 | + ``` |
| 141 | + * facts module is not required to be mentioned |
| 142 | +
|
| 143 | +``` |
| 144 | + --- |
| 145 | + - hosts: localhost |
| 146 | + tasks: |
| 147 | + - name: using system facts |
| 148 | + debug: msg="my os name is {{ ansible_distribution }}" |
| 149 | + |
| 150 | + - name: finding address details of other os |
| 151 | + debug: msg="my os ip details are {{ansible_default_ipv4}} {{ ansible_default_ipv4.macaddress }}" |
| 152 | + |
| 153 | + - name: copy address details of other os |
| 154 | + copy: content="my os ip details are {{ansible_default_ipv4}} {{ ansible_default_ipv4.macaddress }}" dest=/root/ip.txt |
| 155 | +``` |
| 156 | + * name of selinux in ubuntu is apparmor |
| 157 | + * ansible_apparmor is ansible fact used for accessing selinux of other system |
| 158 | +
|
| 159 | +
|
| 160 | +* to install |
| 161 | +``` |
| 162 | + --- |
| 163 | + - hosts: localhost |
| 164 | + tasks: |
| 165 | + - name: install |
| 166 | + yum: |
| 167 | + name: telnet |
| 168 | + state: present |
| 169 | + register: y |
| 170 | + |
| 171 | + - name: output |
| 172 | + debug: var=y |
| 173 | +``` |
| 174 | +
|
| 175 | +* by default ansible gathers facts and to make sure it does not do that |
| 176 | +``` |
| 177 | +gather_facts: no #under hosts file |
| 178 | +``` |
| 179 | +* official website of ansible |
| 180 | +``` |
| 181 | +docs.ansible.com |
| 182 | +``` |
0 commit comments