Changes between Version 81 and Version 82 of GENIExperimenter/Tutorials/AnsibleHelloGENI/Execute
- Timestamp:
- 03/08/21 03:37:08 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GENIExperimenter/Tutorials/AnsibleHelloGENI/Execute
v81 v82 134 134 </td> 135 135 <td> 136 The following are some example Ansible Ad Hoc commands. You can run these commands one at a time from the machine where you have Ansible installed. `- s` tells Ansible to use `sudo` when executing the command. All modules are described in the <a href="http://docs.ansible.com/modules_by_category.html">Ansible Documentation</a>.137 </td> 138 </tr> 139 </table> 140 }}} 141 142 143 [http ://docs.ansible.com/apt_module.html `apt`] module is used to install packages using the `apt` package manager:144 {{{ 145 #!sh 146 ansible [-i inventory] [all/server/client] - s-m apt -a "name=apache2 update_cache=yes"147 }}} 148 149 [http ://docs.ansible.com/command_module.html `command`] module is used to execute an arbitrary command on the remote node:150 {{{ 151 #!sh 152 ansible [-i inventory] [all/server/client] - s-m command -a "/usr/sbin/a2enmod status"153 }}} 154 [http ://docs.ansible.com/file_module.html `file`] module is used to set attributes of files:155 {{{ 156 #!sh 157 ansible [-i inventory] [all/server/client] - s-m file -a "path=/var/www/html state=absent"158 }}} 159 [http ://docs.ansible.com/synchronize_module.html `synchronize`] module is an implementation of `rsync` and is used to efficiently synchronize files between your local machine and a remote node:160 161 {{{ 162 #!sh 163 ansible [-i inventory] [all/server/client] - s-m synchronize \136 The following are some example Ansible Ad Hoc commands. You can run these commands one at a time from the machine where you have Ansible installed. `-b` tells Ansible to use `sudo` when executing the command. All modules are described in the <a href="https://docs.ansible.com/ansible/latest/user_guide/modules_intro.html">Ansible Documentation</a>. 137 </td> 138 </tr> 139 </table> 140 }}} 141 142 143 [https://docs.ansible.com/ansible/2.3/apt_module.html `apt`] module is used to install packages using the `apt` package manager: 144 {{{ 145 #!sh 146 ansible [-i inventory] [all/server/client] -b -m apt -a "name=apache2 update_cache=yes" 147 }}} 148 149 [https://docs.ansible.com/ansible/2.3/command_module.html `command`] module is used to execute an arbitrary command on the remote node: 150 {{{ 151 #!sh 152 ansible [-i inventory] [all/server/client] -b -m command -a "/usr/sbin/a2enmod status" 153 }}} 154 [https://docs.ansible.com/ansible/2.3/file_module.html `file`] module is used to set attributes of files: 155 {{{ 156 #!sh 157 ansible [-i inventory] [all/server/client] -b -m file -a "path=/var/www/html state=absent" 158 }}} 159 [https://docs.ansible.com/ansible/2.4/synchronize_module.html `synchronize`] module is an implementation of `rsync` and is used to efficiently synchronize files between your local machine and a remote node: 160 161 {{{ 162 #!sh 163 ansible [-i inventory] [all/server/client] -b -m synchronize \ 164 164 -a "src=website/index.html dest=/var/www" 165 165 }}} 166 [http ://docs.ansible.com/lineinfile_module.html `lineinfile`] module is used to see if an arbitrary line exists in a file:167 {{{ 168 #!sh 169 ansible [-i inventory] [all/server/client] - s-m lineinfile \166 [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html `lineinfile`] module is used to see if an arbitrary line exists in a file: 167 {{{ 168 #!sh 169 ansible [-i inventory] [all/server/client] -b -m lineinfile \ 170 170 -a "line='ExtendedStatus On' dest=/etc/apache2/conf.d/extendedstatus create=yes state=present" 171 171 }}} 172 [http ://docs.ansible.com/service_module.html `service`] module is used to start/stop/restart/etc services:173 {{{ 174 #!sh 175 ansible [-i inventory] [all/server/client] - s-m service -a "name=apache2 state=restarted"172 [https://docs.ansible.com/ansible/2.9_ja/modules/service_module.html `service`] module is used to start/stop/restart/etc services: 173 {{{ 174 #!sh 175 ansible [-i inventory] [all/server/client] -b -m service -a "name=apache2 state=restarted" 176 176 }}} 177 177 }}} … … 232 232 - name: Configure client 233 233 hosts: client 234 sudo: True235 234 tasks: 236 235 - name: install apache2 237 236 apt: name=apache2 update_cache=yes 237 become: yes 238 238 - name: install iperf 239 239 apt: name=iperf update_cache=yes 240 become: yes 240 241 - name: copy scripts into /local with permissions 755 241 242 synchronize: src=scripts dest=/local mode=755 242 243 }}} 244 become: yes 243 245 244 246 ''Do these commands look like the Ad Hoc commands you came up with in the previous step?'' … … 263 265 - name: Configure server 264 266 hosts: server 265 sudo: True266 267 tasks: 267 268 - name: install apache2 268 269 apt: name=apache2 update_cache=yes 270 become: yes 269 271 - name: install iperf 270 272 apt: name=iperf update_cache=yes 273 become: yes 271 274 - name: /usr/sbin/a2enmod status 272 275 # INSERT COMMAND HERE … … 331 334 {{{ 332 335 #!sh 333 ansible -i inventory server - s-m shell -a "iperf -s -i 10 &> /var/www/iperflogs/iperf-server.log"336 ansible -i inventory server -b -m shell -a "iperf -s -i 10 &> /var/www/iperflogs/iperf-server.log" 334 337 }}} 335 338 On the local node do: 336 339 {{{ 337 340 #!sh 338 ansible -i inventory client - s-m shell -a "/local/scripts/client-wget.sh &"339 ansible -i inventory client - s-m shell -a "/local/scripts/client-iperf.sh &"341 ansible -i inventory client -b -m shell -a "/local/scripts/client-wget.sh &" 342 ansible -i inventory client -b -m shell -a "/local/scripts/client-iperf.sh &" 340 343 }}} 341 344 }}}