User Tools

Site Tools


automation:ansible

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

automation:ansible [2023/05/29 12:46] – w jotasandokuautomation:ansible [2023/11/02 14:38] (current) – external edit 127.0.0.1
Line 87: Line 87:
   * -a : arguments   * -a : arguments
  
-  ansible all -i inventory -m setup    # this collects facts 
   ansible all -i inventory -m setup    # this collects facts   ansible all -i inventory -m setup    # this collects facts
   ansible -i hosts all -m ping --private-key /home/student/ansible_key  # PING module, useful to test connectivity to the hosts   ansible -i hosts all -m ping --private-key /home/student/ansible_key  # PING module, useful to test connectivity to the hosts
Line 358: Line 357:
   * This is a loop traversing a **list of dictionaries**: [[https://github.com/sandervanvugt/ansiblefundamentals/blob/master/loop_on_vars.yaml]]   * This is a loop traversing a **list of dictionaries**: [[https://github.com/sandervanvugt/ansiblefundamentals/blob/master/loop_on_vars.yaml]]
   * Legacy with_ syntax   * Legacy with_ syntax
-    * with_items is equivalent to modern ''loop'+    * with_items is equivalent to modern ''loop''
     * ''with_file'' :  the item contains a file, which contents are used to loop through     * ''with_file'' :  the item contains a file, which contents are used to loop through
 +    * In modern ansible, most of the ''with'' can be replaced with **filters**
  
 ---- ----
Line 407: Line 407:
 __ASSERT__ __ASSERT__
 \\ \\
-Checks the **veracity** of an expression. See [[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/assert_module.html]]+Checks the **veracity** of an expression A bot like the fail module but with more advanced features. 
 +  * Also uses these keywords''fail_msg'' and ''success_msg''
 \\ \\
 Example: Example:
  
-  ~ name: "ASSERT >> Ensure VPN3 RT difference succeeded+  ~~~ 
-    assert+  - hosts: localhost 
-      that: +    vars_prompt: 
-        - "rt_updates[2]['name'== 'VPN3'+    - name: filesize 
-        "rt_updates[2]['description'] == 'third VRF'"+      prompt: "specify file size" 
 +      private: no 
 +    tasks 
 +    - name: check file size is valid 
 +      assert: 
 +        that: 
 +        - filesize <100 
 +        - filesize >
 +        fail_msg: "size has to be between 0 and 100!
 +        success_msg: "correct size, continue" 
 +         
 +        
  
  
Line 445: Line 457:
  
  
-__**ROLES** and Junos specifics __+__**ROLES**__ 
 +  * Roles can be downloaded from galaxy as part of collections. 
 +  * We can also ''create our own roles'': 
 +  * first we create the dir with subfolders: defaults, handlers, meta, tasks, templates, vars 
 +  * This is an example of a custom role: [[https://github.com/sandervanvugt/rhce8-live/tree/0fd56c840f683af72a74647ad2f7118555153425/lesson11/roles/motd]] 
 + 
 +  ansible-galaxy role init <my-role> 
 + 
 + 
 +---- 
 + 
 +__roles for Junos __
 \\ \\
   * Roles (network engine role) act as wrappers. They allows us to use a yaml based parser (command_parser) instead of custom filters. This way, we make the code much shorter.   * Roles (network engine role) act as wrappers. They allows us to use a yaml based parser (command_parser) instead of custom filters. This way, we make the code much shorter.
Line 508: Line 531:
     set_fact:     set_fact:
       rt_updates: "{{ int_vrf_list | rt_diff(run_vrf_dict) }}"       rt_updates: "{{ int_vrf_list | rt_diff(run_vrf_dict) }}"
 +      
 +
 +----
 +__MANAGE FAILURES__
 +\\
 +  * ''ignore_errors''
 +  * ''force_handlers'' : to force a handler that has been triggered to run, even if (another) task fails.
 +  * [[https://stackoverflow.com/questions/42653655/ansible-ignore-errors-when|External Link]]
 +
 +
 +----
 +__AWX__
 +\\
 +  * Ansible Tower == AWS  =~ 'Ansible Automation Platform' (this latter is sold now by redhat)
 +  * {{ :automation:awx-sander-van-vugt.pdf |}}
 +  * **AWX uses k8s extensively**
 +Install minikube (ubuntu) with:
 +  minikube start --cpus=4 --memory=6g --addons=ingress --vm-driver=docker
automation/ansible.1685364387.txt.gz · Last modified: (external edit)