kandi background
Explore Kits

ansible | radically simple IT automation platform | DevOps library

 by   ansible Python Version: v2.5.0b1 License: GPL-3.0

 by   ansible Python Version: v2.5.0b1 License: GPL-3.0

Download this library from

kandi X-RAY | ansible Summary

ansible is a Python library typically used in Devops, Ansible, Docker applications. ansible has no bugs, it has build file available, it has a Strong Copyleft License and it has high support. However ansible has 8 vulnerabilities. You can install using 'pip install ansible' or download it from GitHub, PyPI.
Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • ansible has a highly active ecosystem.
  • It has 52834 star(s) with 21799 fork(s). There are 1978 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 814 open issues and 29486 have been closed. On average issues are closed in 425 days. There are 396 open pull requests and 0 closed requests.
  • It has a negative sentiment in the developer community.
  • The latest version of ansible is v2.5.0b1
ansible Support
Best in #DevOps
Average in #DevOps
ansible Support
Best in #DevOps
Average in #DevOps

quality kandi Quality

  • ansible has 0 bugs and 0 code smells.
ansible Quality
Best in #DevOps
Average in #DevOps
ansible Quality
Best in #DevOps
Average in #DevOps

securitySecurity

  • ansible has 8 vulnerability issues reported (0 critical, 1 high, 5 medium, 2 low).
  • ansible code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
ansible Security
Best in #DevOps
Average in #DevOps
ansible Security
Best in #DevOps
Average in #DevOps

license License

  • ansible is licensed under the GPL-3.0 License. This license is Strong Copyleft.
  • Strong Copyleft licenses enforce sharing, and you can use them when creating open source projects.
ansible License
Best in #DevOps
Average in #DevOps
ansible License
Best in #DevOps
Average in #DevOps

buildReuse

  • ansible releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • ansible saves you 1647488 person hours of effort in developing the same functionality from scratch.
  • It has 701196 lines of code, 24946 functions and 3494 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
ansible Reuse
Best in #DevOps
Average in #DevOps
ansible Reuse
Best in #DevOps
Average in #DevOps
Top functions reviewed by kandi - BETA

kandi has reviewed ansible and discovered the below as its top functions. This is intended to give you an instant insight into ansible implemented functionality, and help decide if they suit your requirements.

  • Run AnsibleModule
    • Return an error message about the required library
    • Convert obj to text
    • Spawn the daemon
    • Create a symlink
    • Convert obj to bytes
    • Ensures that the file is present in the destination
    • Sets the mode of the given path
    • Recursively change ownership of a directory
    • Run a wrapped module
    • Construct a rule string
    • Enforces the host state
  • Determine if this file is unarchived
    • List all files in the archive
    • Convert a permstr to octal mode
    • Return CRC32 for a given path
  • Get service tools
    • Get the status of the service
      • Recursively change the owner of a directory
        • Enable the service
          • Return distro release info
            • Runs Ansible module
              • Create a new user
                • Construct the rule
                  • Enforce the state of a host
                    • Set the mode of a file or a diff
                      • Enable the service
                        • Modify usermod
                          • Ensures that a file exists
                            • Modify the user
                              • Enable new service
                                • Ensure a symlink exists
                                  • Start the daemon
                                    • Create a user

                                      Get all kandi verified functions for this library.

                                      Get all kandi verified functions for this library.

                                      ansible Key Features

                                      Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.

                                      ansible Examples and Code Snippets

                                      See all related Code Snippets

                                      Ansible playbook loop from site yaml or template?

                                      copy iconCopydownload iconDownload
                                      - set_fact:
                                          full_device_name: >-
                                            {{ 
                                              full_device_name 
                                              | default([]) 
                                              + [
                                                device_name | lower ~ '-' ~ 
                                                site_abbrev | lower ~ '-' ~ 
                                                item.installation_floor  ~  
                                                "%02d" | format(item.id) ~ '.txt'
                                              ]
                                            }}
                                        loop: "{{ switch_stacks }}"
                                        when: device_type == 'switch'
                                      
                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      - hosts: localhost
                                        gather_facts: false
                                      
                                        tasks:
                                          - set_fact:
                                              full_device_name: >-
                                                {{ 
                                                  full_device_name 
                                                  | default([]) 
                                                  + [
                                                    device_name | lower ~ '-' ~ 
                                                    site_abbrev | lower ~ '-' ~ 
                                                    item.installation_floor  ~  
                                                    "%02d" | format(item.id) ~ '.txt'
                                                  ]
                                                }}
                                            loop: "{{ switch_stacks }}"
                                            when: device_type == 'switch'
                                            vars:
                                              device_name: swi
                                              site_abbrev: lon
                                              device_type: switch
                                              switch_stacks:
                                                - id: 01
                                                  installation_floor: 1
                                                - id: 02
                                                  installation_floor: 2
                                      
                                          - debug: 
                                              var: full_device_name
                                      
                                      TASK [set_fact] ************************************************************
                                      ok: [localhost] => (item={'id': 1, 'installation_floor': 1})
                                      ok: [localhost] => (item={'id': 2, 'installation_floor': 2})
                                      
                                      TASK [debug] ***************************************************************
                                      ok: [localhost] => 
                                        full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      - set_fact:
                                          full_device_name: >-
                                            {{ 
                                              full_device_name 
                                              | default([]) 
                                              + [
                                                device_name | lower ~ '-' ~ 
                                                site_abbrev | lower ~ '-' ~ 
                                                item.installation_floor  ~  
                                                "%02d" | format(item.id) ~ '.txt'
                                              ]
                                            }}
                                        loop: "{{ switch_stacks }}"
                                        when: device_type == 'switch'
                                      
                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      - hosts: localhost
                                        gather_facts: false
                                      
                                        tasks:
                                          - set_fact:
                                              full_device_name: >-
                                                {{ 
                                                  full_device_name 
                                                  | default([]) 
                                                  + [
                                                    device_name | lower ~ '-' ~ 
                                                    site_abbrev | lower ~ '-' ~ 
                                                    item.installation_floor  ~  
                                                    "%02d" | format(item.id) ~ '.txt'
                                                  ]
                                                }}
                                            loop: "{{ switch_stacks }}"
                                            when: device_type == 'switch'
                                            vars:
                                              device_name: swi
                                              site_abbrev: lon
                                              device_type: switch
                                              switch_stacks:
                                                - id: 01
                                                  installation_floor: 1
                                                - id: 02
                                                  installation_floor: 2
                                      
                                          - debug: 
                                              var: full_device_name
                                      
                                      TASK [set_fact] ************************************************************
                                      ok: [localhost] => (item={'id': 1, 'installation_floor': 1})
                                      ok: [localhost] => (item={'id': 2, 'installation_floor': 2})
                                      
                                      TASK [debug] ***************************************************************
                                      ok: [localhost] => 
                                        full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      - set_fact:
                                          full_device_name: >-
                                            {{ 
                                              full_device_name 
                                              | default([]) 
                                              + [
                                                device_name | lower ~ '-' ~ 
                                                site_abbrev | lower ~ '-' ~ 
                                                item.installation_floor  ~  
                                                "%02d" | format(item.id) ~ '.txt'
                                              ]
                                            }}
                                        loop: "{{ switch_stacks }}"
                                        when: device_type == 'switch'
                                      
                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      - hosts: localhost
                                        gather_facts: false
                                      
                                        tasks:
                                          - set_fact:
                                              full_device_name: >-
                                                {{ 
                                                  full_device_name 
                                                  | default([]) 
                                                  + [
                                                    device_name | lower ~ '-' ~ 
                                                    site_abbrev | lower ~ '-' ~ 
                                                    item.installation_floor  ~  
                                                    "%02d" | format(item.id) ~ '.txt'
                                                  ]
                                                }}
                                            loop: "{{ switch_stacks }}"
                                            when: device_type == 'switch'
                                            vars:
                                              device_name: swi
                                              site_abbrev: lon
                                              device_type: switch
                                              switch_stacks:
                                                - id: 01
                                                  installation_floor: 1
                                                - id: 02
                                                  installation_floor: 2
                                      
                                          - debug: 
                                              var: full_device_name
                                      
                                      TASK [set_fact] ************************************************************
                                      ok: [localhost] => (item={'id': 1, 'installation_floor': 1})
                                      ok: [localhost] => (item={'id': 2, 'installation_floor': 2})
                                      
                                      TASK [debug] ***************************************************************
                                      ok: [localhost] => 
                                        full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      - set_fact:
                                          full_device_name: >-
                                            {{ 
                                              full_device_name 
                                              | default([]) 
                                              + [
                                                device_name | lower ~ '-' ~ 
                                                site_abbrev | lower ~ '-' ~ 
                                                item.installation_floor  ~  
                                                "%02d" | format(item.id) ~ '.txt'
                                              ]
                                            }}
                                        loop: "{{ switch_stacks }}"
                                        when: device_type == 'switch'
                                      
                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      - hosts: localhost
                                        gather_facts: false
                                      
                                        tasks:
                                          - set_fact:
                                              full_device_name: >-
                                                {{ 
                                                  full_device_name 
                                                  | default([]) 
                                                  + [
                                                    device_name | lower ~ '-' ~ 
                                                    site_abbrev | lower ~ '-' ~ 
                                                    item.installation_floor  ~  
                                                    "%02d" | format(item.id) ~ '.txt'
                                                  ]
                                                }}
                                            loop: "{{ switch_stacks }}"
                                            when: device_type == 'switch'
                                            vars:
                                              device_name: swi
                                              site_abbrev: lon
                                              device_type: switch
                                              switch_stacks:
                                                - id: 01
                                                  installation_floor: 1
                                                - id: 02
                                                  installation_floor: 2
                                      
                                          - debug: 
                                              var: full_device_name
                                      
                                      TASK [set_fact] ************************************************************
                                      ok: [localhost] => (item={'id': 1, 'installation_floor': 1})
                                      ok: [localhost] => (item={'id': 2, 'installation_floor': 2})
                                      
                                      TASK [debug] ***************************************************************
                                      ok: [localhost] => 
                                        full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      switch_stacks:
                                        - id: '01'
                                          installation_floor: 1
                                        - id: '02'
                                          installation_floor: 2
                                      
                                          - set_fact:
                                              full_device_name: "{{ [prefix]|product(sw_fl_id)|map('join')|
                                                                             product([postfix])|map('join')|list }}"
                                            vars:
                                              prefix: "{{ device_name }}-{{ site_abbrev }}-"
                                              postfix: ".txt"
                                              sw_id: "{{ switch_stacks|map(attribute='id')|list }}"
                                              sw_fl: "{{ switch_stacks|map(attribute='installation_floor')|list }}"
                                              sw_fl_id: "{{ sw_fl|zip(sw_id)|map('join')|list }}"
                                      
                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      switch_stacks:
                                        - id: '01'
                                          installation_floor: 1
                                        - id: '02'
                                          installation_floor: 2
                                      
                                          - set_fact:
                                              full_device_name: "{{ [prefix]|product(sw_fl_id)|map('join')|
                                                                             product([postfix])|map('join')|list }}"
                                            vars:
                                              prefix: "{{ device_name }}-{{ site_abbrev }}-"
                                              postfix: ".txt"
                                              sw_id: "{{ switch_stacks|map(attribute='id')|list }}"
                                              sw_fl: "{{ switch_stacks|map(attribute='installation_floor')|list }}"
                                              sw_fl_id: "{{ sw_fl|zip(sw_id)|map('join')|list }}"
                                      
                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                      switch_stacks:
                                        - id: '01'
                                          installation_floor: 1
                                        - id: '02'
                                          installation_floor: 2
                                      
                                          - set_fact:
                                              full_device_name: "{{ [prefix]|product(sw_fl_id)|map('join')|
                                                                             product([postfix])|map('join')|list }}"
                                            vars:
                                              prefix: "{{ device_name }}-{{ site_abbrev }}-"
                                              postfix: ".txt"
                                              sw_id: "{{ switch_stacks|map(attribute='id')|list }}"
                                              sw_fl: "{{ switch_stacks|map(attribute='installation_floor')|list }}"
                                              sw_fl_id: "{{ sw_fl|zip(sw_id)|map('join')|list }}"
                                      
                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      
                                          name: Set Destination Directory & Filename for Switch Configurations
                                        set_fact:
                                          dest_dir: /home/usr/complete_config/{{ project_name }}
                                          full_device_name: >-
                                            {{
                                                device_name | lower ~ '-' ~
                                                site_abbrev | lower ~ '-' ~
                                                item.installation_floor  ~
                                                "%02d" | format(item.id)
                                      
                                            }}
                                        loop: "{{ switch_stacks }}"
                                        when: device_type == 'switch'
                                      

                                      Line too long: Ansible lint

                                      copy iconCopydownload iconDownload
                                          url: "https://{{ vertex_region }}-aiplatform.googleapis.com/v1/projects/\
                                               {{ project }}/locations/{{ vertex_region }}/datasets/{{ dataset_id }}/dataItems"
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      - name: Demo debug with variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                        vars:
                                          vertex_region: foo_region
                                          dataset_id: bar_id
                                          project: bar_project
                                      
                                      - name: Demo debug without variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      TASK [Demo debug with variable] ******************************************************************
                                      ok: [localhost] => 
                                        msg: https://foo_region-aiplatform.googleapis.com/v1/projects/bar_project/locations/foo_region/datasets/bar_id/dataItems
                                      
                                      TASK [Demo debug without variable] ***************************************************************
                                      ok: [localhost] => 
                                        msg: https://this_is_a_super_long_url_that_looks_like_it_cannot_be_split_into_multiples_lines_is_it_question_mark.co.uk
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      - name: Demo debug with variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                        vars:
                                          vertex_region: foo_region
                                          dataset_id: bar_id
                                          project: bar_project
                                      
                                      - name: Demo debug without variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      TASK [Demo debug with variable] ******************************************************************
                                      ok: [localhost] => 
                                        msg: https://foo_region-aiplatform.googleapis.com/v1/projects/bar_project/locations/foo_region/datasets/bar_id/dataItems
                                      
                                      TASK [Demo debug without variable] ***************************************************************
                                      ok: [localhost] => 
                                        msg: https://this_is_a_super_long_url_that_looks_like_it_cannot_be_split_into_multiples_lines_is_it_question_mark.co.uk
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      - name: Demo debug with variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                        vars:
                                          vertex_region: foo_region
                                          dataset_id: bar_id
                                          project: bar_project
                                      
                                      - name: Demo debug without variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      TASK [Demo debug with variable] ******************************************************************
                                      ok: [localhost] => 
                                        msg: https://foo_region-aiplatform.googleapis.com/v1/projects/bar_project/locations/foo_region/datasets/bar_id/dataItems
                                      
                                      TASK [Demo debug without variable] ***************************************************************
                                      ok: [localhost] => 
                                        msg: https://this_is_a_super_long_url_that_looks_like_it_cannot_be_split_into_multiples_lines_is_it_question_mark.co.uk
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                      
                                      - ansible.builtin.uri:
                                          url: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      - name: Demo debug with variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://
                                            {{- vertex_region -}}
                                            -aiplatform.googleapis.com/v1/projects/
                                            {{- project -}}
                                            /locations/
                                            {{- vertex_region -}}
                                            /datasets/
                                            {{- dataset_id -}}
                                            /dataItems
                                        vars:
                                          vertex_region: foo_region
                                          dataset_id: bar_id
                                          project: bar_project
                                      
                                      - name: Demo debug without variable
                                        ansible.builtin.debug:
                                          msg: >-
                                            https://this_is_a_super_long_url_
                                            {#- -#}
                                            that_looks_like_it_cannot_be_split_
                                            {#- -#}
                                            into_multiples_lines_is_it_
                                            {#- -#}
                                            question_mark.co.uk
                                      
                                      TASK [Demo debug with variable] ******************************************************************
                                      ok: [localhost] => 
                                        msg: https://foo_region-aiplatform.googleapis.com/v1/projects/bar_project/locations/foo_region/datasets/bar_id/dataItems
                                      
                                      TASK [Demo debug without variable] ***************************************************************
                                      ok: [localhost] => 
                                        msg: https://this_is_a_super_long_url_that_looks_like_it_cannot_be_split_into_multiples_lines_is_it_question_mark.co.uk
                                      

                                      Ansible update variable in function

                                      copy iconCopydownload iconDownload
                                      - name: Delete old versions
                                        ansible.builtin.file:
                                          path: "{{ item.path }}"
                                          state: absent
                                        loop: "{{ file_stat.files[:-3] }}"
                                      
                                      loop: "{{ (file_stat.files | sort(attribute='ctime'))[:-3] }}"
                                      
                                      - name: Delete old versions
                                        ansible.builtin.file:
                                          path: "{{ item.path }}"
                                          state: absent
                                        loop: "{{ file_stat.files[:-3] }}"
                                      
                                      loop: "{{ (file_stat.files | sort(attribute='ctime'))[:-3] }}"
                                      

                                      Can I specify that an argument can't be used with a specific choice in Ansible module spec?

                                      copy iconCopydownload iconDownload
                                      arguments = dict(
                                          username=dict(type='str', required=True),
                                          password=dict(type='str', no_log=True, required=False),
                                          sid=dict(type='str', required=False),
                                          login_type=dict(
                                              type='str',
                                              choices=[ 'sql', 'windows' ],
                                              default='sql',
                                              required=False
                                                  )
                                      )
                                      module = AnsibleModule(
                                          argument_spec=arguments,
                                          required_if=[
                                              ('login_type', 'sql', ('password',)),
                                          ],
                                          supports_check_mode=True
                                      )
                                      
                                      if module.params['login_type'] == 'windows' and (module.params['password'] or module.params['sid']):
                                          module.fail_json(msg="unable to use 'login_type=windows' with args 'password' or 'sid'")
                                      
                                      required_if=[
                                          ('login_type', 'sql', ('password'**,**)),
                                      ],
                                      
                                      arguments = dict(
                                          username=dict(type='str', required=True),
                                          password=dict(type='str', no_log=True, required=False),
                                          sid=dict(type='str', required=False),
                                          login_type=dict(
                                              type='str',
                                              choices=[ 'sql', 'windows' ],
                                              default='sql',
                                              required=False
                                                  )
                                      )
                                      module = AnsibleModule(
                                          argument_spec=arguments,
                                          required_if=[
                                              ('login_type', 'sql', ('password',)),
                                          ],
                                          supports_check_mode=True
                                      )
                                      
                                      if module.params['login_type'] == 'windows' and (module.params['password'] or module.params['sid']):
                                          module.fail_json(msg="unable to use 'login_type=windows' with args 'password' or 'sid'")
                                      
                                      required_if=[
                                          ('login_type', 'sql', ('password'**,**)),
                                      ],
                                      

                                      Ansible: how to achieve idempotence with tasks that append files on host (w/o reverting to initial state)

                                      copy iconCopydownload iconDownload
                                      - name: Configure filebeat modules
                                        hosts: all
                                      
                                        vars:
                                          fb_modules_d:
                                            - file: module1.yml
                                              state: present
                                            - file: module2.yml
                                              state: present
                                            - file: module3.yml
                                              state: absent
                                      
                                        tasks:
                                          - name: Make sure all needed module files are present
                                            template:
                                              src: "modules.d/{{ item.file }}"
                                              dest: "/etc/filebeat/modules.d/{{ item.file }}"
                                              mode: '0644'
                                            loop: "{{ fb_modules_d | selectattr('state', '==', 'present') }}"
                                            notifiy: restart_filebeat
                                       
                                          - name: Make sure all disabled modules are removed
                                            file:
                                              dest: "/etc/filebeat/modules.d/{{ item.file }}"
                                              state: "{{ item.state }}"
                                            loop: loop: "{{ fb_modules_d | selectattr('state', '==', 'absent') }}"
                                            notify: restart_filebeat
                                      
                                        handlers:
                                          - name: Restart filebeat service
                                            listen: restart_filebeat
                                            systemd:
                                              name: filebeat
                                              state: restarted
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      └── module99.yml
                                      
                                      shell> cat playbook.yml
                                      - name: Configure filebeat modules
                                        hosts: localhost
                                      
                                        vars:
                                          fb_modules_path: etc/filebeat/modules.d
                                          fb_modules_d:
                                            - module1.yml
                                            - module2.yml
                                            - module3.yml
                                      
                                        tasks:
                                          - name: Create modules
                                            template:
                                              src: "modules.d/{{ item }}"
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              mode: '0644'
                                            loop: "{{ fb_modules_d }}"
                                            notify: restart_filebeat
                                      
                                          - name: Remove modules
                                            file:
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              state: absent
                                            loop: "{{ query('fileglob', fb_modules_path ~ '/*')|
                                                      map('basename')|
                                                      difference(fb_modules_d) }}"
                                            notify: restart_filebeat
                                      
                                        handlers:
                                          - name: Restart filebeat service
                                            listen: restart_filebeat
                                      #     systemd:
                                      #       name: filebeat
                                      #       state: restarted
                                            debug:
                                              msg: Restart filebeat
                                      
                                      TASK [Create modules] ***************************************************
                                      changed: [localhost] => (item=module1.yml)
                                      changed: [localhost] => (item=module2.yml)
                                      changed: [localhost] => (item=module3.yml)
                                      
                                      TASK [Remove modules] ***************************************************
                                      changed: [localhost] => (item=module99.yml)
                                      
                                      RUNNING HANDLER [Restart filebeat service] ******************************
                                      ok: [localhost] => 
                                        msg: Restart filebeat
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      ├── module1.yml
                                      ├── module2.yml
                                      └── module3.yml
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      └── module99.yml
                                      
                                      shell> cat playbook.yml
                                      - name: Configure filebeat modules
                                        hosts: localhost
                                      
                                        vars:
                                          fb_modules_path: etc/filebeat/modules.d
                                          fb_modules_d:
                                            - module1.yml
                                            - module2.yml
                                            - module3.yml
                                      
                                        tasks:
                                          - name: Create modules
                                            template:
                                              src: "modules.d/{{ item }}"
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              mode: '0644'
                                            loop: "{{ fb_modules_d }}"
                                            notify: restart_filebeat
                                      
                                          - name: Remove modules
                                            file:
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              state: absent
                                            loop: "{{ query('fileglob', fb_modules_path ~ '/*')|
                                                      map('basename')|
                                                      difference(fb_modules_d) }}"
                                            notify: restart_filebeat
                                      
                                        handlers:
                                          - name: Restart filebeat service
                                            listen: restart_filebeat
                                      #     systemd:
                                      #       name: filebeat
                                      #       state: restarted
                                            debug:
                                              msg: Restart filebeat
                                      
                                      TASK [Create modules] ***************************************************
                                      changed: [localhost] => (item=module1.yml)
                                      changed: [localhost] => (item=module2.yml)
                                      changed: [localhost] => (item=module3.yml)
                                      
                                      TASK [Remove modules] ***************************************************
                                      changed: [localhost] => (item=module99.yml)
                                      
                                      RUNNING HANDLER [Restart filebeat service] ******************************
                                      ok: [localhost] => 
                                        msg: Restart filebeat
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      ├── module1.yml
                                      ├── module2.yml
                                      └── module3.yml
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      └── module99.yml
                                      
                                      shell> cat playbook.yml
                                      - name: Configure filebeat modules
                                        hosts: localhost
                                      
                                        vars:
                                          fb_modules_path: etc/filebeat/modules.d
                                          fb_modules_d:
                                            - module1.yml
                                            - module2.yml
                                            - module3.yml
                                      
                                        tasks:
                                          - name: Create modules
                                            template:
                                              src: "modules.d/{{ item }}"
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              mode: '0644'
                                            loop: "{{ fb_modules_d }}"
                                            notify: restart_filebeat
                                      
                                          - name: Remove modules
                                            file:
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              state: absent
                                            loop: "{{ query('fileglob', fb_modules_path ~ '/*')|
                                                      map('basename')|
                                                      difference(fb_modules_d) }}"
                                            notify: restart_filebeat
                                      
                                        handlers:
                                          - name: Restart filebeat service
                                            listen: restart_filebeat
                                      #     systemd:
                                      #       name: filebeat
                                      #       state: restarted
                                            debug:
                                              msg: Restart filebeat
                                      
                                      TASK [Create modules] ***************************************************
                                      changed: [localhost] => (item=module1.yml)
                                      changed: [localhost] => (item=module2.yml)
                                      changed: [localhost] => (item=module3.yml)
                                      
                                      TASK [Remove modules] ***************************************************
                                      changed: [localhost] => (item=module99.yml)
                                      
                                      RUNNING HANDLER [Restart filebeat service] ******************************
                                      ok: [localhost] => 
                                        msg: Restart filebeat
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      ├── module1.yml
                                      ├── module2.yml
                                      └── module3.yml
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      └── module99.yml
                                      
                                      shell> cat playbook.yml
                                      - name: Configure filebeat modules
                                        hosts: localhost
                                      
                                        vars:
                                          fb_modules_path: etc/filebeat/modules.d
                                          fb_modules_d:
                                            - module1.yml
                                            - module2.yml
                                            - module3.yml
                                      
                                        tasks:
                                          - name: Create modules
                                            template:
                                              src: "modules.d/{{ item }}"
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              mode: '0644'
                                            loop: "{{ fb_modules_d }}"
                                            notify: restart_filebeat
                                      
                                          - name: Remove modules
                                            file:
                                              dest: "{{ fb_modules_path }}/{{ item }}"
                                              state: absent
                                            loop: "{{ query('fileglob', fb_modules_path ~ '/*')|
                                                      map('basename')|
                                                      difference(fb_modules_d) }}"
                                            notify: restart_filebeat
                                      
                                        handlers:
                                          - name: Restart filebeat service
                                            listen: restart_filebeat
                                      #     systemd:
                                      #       name: filebeat
                                      #       state: restarted
                                            debug:
                                              msg: Restart filebeat
                                      
                                      TASK [Create modules] ***************************************************
                                      changed: [localhost] => (item=module1.yml)
                                      changed: [localhost] => (item=module2.yml)
                                      changed: [localhost] => (item=module3.yml)
                                      
                                      TASK [Remove modules] ***************************************************
                                      changed: [localhost] => (item=module99.yml)
                                      
                                      RUNNING HANDLER [Restart filebeat service] ******************************
                                      ok: [localhost] => 
                                        msg: Restart filebeat
                                      
                                      shell> tree etc/filebeat/modules.d
                                      etc/filebeat/modules.d
                                      ├── module1.yml
                                      ├── module2.yml
                                      └── module3.yml
                                      

                                      Ansible: Show last X output lines

                                      copy iconCopydownload iconDownload
                                      - debug: 
                                          var: ps.stdout_lines[-5:]
                                      
                                      - command: printf "line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10"
                                        register: ps
                                      
                                      - debug: 
                                          var: ps.stdout_lines[-5:]
                                      
                                      TASK [command] ************************************************************
                                      changed: [localhost]
                                      
                                      TASK [debug] **************************************************************
                                      ok: [localhost] => 
                                        ps.stdout_lines[-5:]:
                                        - line6
                                        - line7
                                        - line8
                                        - line9
                                        - line10
                                      
                                      - debug: 
                                          var: ps.stdout_lines[-5:]
                                      
                                      - command: printf "line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10"
                                        register: ps
                                      
                                      - debug: 
                                          var: ps.stdout_lines[-5:]
                                      
                                      TASK [command] ************************************************************
                                      changed: [localhost]
                                      
                                      TASK [debug] **************************************************************
                                      ok: [localhost] => 
                                        ps.stdout_lines[-5:]:
                                        - line6
                                        - line7
                                        - line8
                                        - line9
                                        - line10
                                      
                                      - debug: 
                                          var: ps.stdout_lines[-5:]
                                      
                                      - command: printf "line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10"
                                        register: ps
                                      
                                      - debug: 
                                          var: ps.stdout_lines[-5:]
                                      
                                      TASK [command] ************************************************************
                                      changed: [localhost]
                                      
                                      TASK [debug] **************************************************************
                                      ok: [localhost] => 
                                        ps.stdout_lines[-5:]:
                                        - line6
                                        - line7
                                        - line8
                                        - line9
                                        - line10
                                      

                                      Ansible, how to set a global fact using roles?

                                      copy iconCopydownload iconDownload
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: VARIABLE IS NOT DEFINED!
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                            run_once: true
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: K10cf129cfedaf
                                      
                                          - name: Set Node-Token fact
                                            set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: server_role == "master"
                                            run_once: true
                                      
                                          - set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: inventory_hostname == 'master'
                                          - set_fact:
                                              nodeToken: "{{ hostvars['master'].nodeToken }}"
                                            run_once: true
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: VARIABLE IS NOT DEFINED!
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                            run_once: true
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: K10cf129cfedaf
                                      
                                          - name: Set Node-Token fact
                                            set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: server_role == "master"
                                            run_once: true
                                      
                                          - set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: inventory_hostname == 'master'
                                          - set_fact:
                                              nodeToken: "{{ hostvars['master'].nodeToken }}"
                                            run_once: true
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: VARIABLE IS NOT DEFINED!
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                            run_once: true
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: K10cf129cfedaf
                                      
                                          - name: Set Node-Token fact
                                            set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: server_role == "master"
                                            run_once: true
                                      
                                          - set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: inventory_hostname == 'master'
                                          - set_fact:
                                              nodeToken: "{{ hostvars['master'].nodeToken }}"
                                            run_once: true
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: VARIABLE IS NOT DEFINED!
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                            run_once: true
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: K10cf129cfedaf
                                      
                                          - name: Set Node-Token fact
                                            set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: server_role == "master"
                                            run_once: true
                                      
                                          - set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: inventory_hostname == 'master'
                                          - set_fact:
                                              nodeToken: "{{ hostvars['master'].nodeToken }}"
                                            run_once: true
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: VARIABLE IS NOT DEFINED!
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                            run_once: true
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: K10cf129cfedaf
                                      
                                          - name: Set Node-Token fact
                                            set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: server_role == "master"
                                            run_once: true
                                      
                                          - set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: inventory_hostname == 'master'
                                          - set_fact:
                                              nodeToken: "{{ hostvars['master'].nodeToken }}"
                                            run_once: true
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: VARIABLE IS NOT DEFINED!
                                      
                                      - hosts: master,node
                                        tasks:
                                          - set_fact:
                                              nodeToken: K10cf129cfedaf
                                            when: inventory_hostname == 'master'
                                            run_once: true
                                          - debug:
                                              var: nodeToken
                                      
                                      ok: [master] => 
                                        nodeToken: K10cf129cfedaf
                                      ok: [node] => 
                                        nodeToken: K10cf129cfedaf
                                      
                                          - name: Set Node-Token fact
                                            set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: server_role == "master"
                                            run_once: true
                                      
                                          - set_fact:
                                              nodeToken: "{{ nodetoken.stdout }}"
                                            when: inventory_hostname == 'master'
                                          - set_fact:
                                              nodeToken: "{{ hostvars['master'].nodeToken }}"
                                            run_once: true
                                      
                                      - hosts: all
                                        gather_facts: no
                                      
                                        tasks:
                                          - set_fact:
                                              master_node: "{{ inventory_hostname }}"
                                            when: server_role == 'master'
                                            delegate_to: localhost
                                            delegate_facts: true
                                      
                                          - set_fact:
                                              token: 12345678
                                            run_once: true
                                            delegate_to: "{{ hostvars.localhost.master_node }}"
                                            delegate_facts: true
                                      
                                          - debug:
                                              var: hostvars[hostvars.localhost.master_node].token
                                            when: server_role != 'master'
                                      
                                      PLAY [all] ********************************************************************************************************
                                      
                                      TASK [set_fact] ***************************************************************************************************
                                      skipping: [node1]
                                      ok: [node2 -> localhost]
                                      skipping: [node3]
                                      
                                      TASK [set_fact] ***************************************************************************************************
                                      ok: [node1 -> node2]
                                      
                                      TASK [debug] ******************************************************************************************************
                                      skipping: [node2]
                                      ok: [node1] => 
                                        hostvars[hostvars.localhost.master_node].token: '12345678'
                                      ok: [node3] => 
                                        hostvars[hostvars.localhost.master_node].token: '12345678'
                                      
                                      PLAY RECAP ********************************************************************************************************
                                      node1                      : ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
                                      node2                      : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
                                      node3                      : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
                                      
                                      - hosts: all
                                        gather_facts: no
                                      
                                        tasks:
                                          - set_fact:
                                              master_node: "{{ inventory_hostname }}"
                                            when: server_role == 'master'
                                            delegate_to: localhost
                                            delegate_facts: true
                                      
                                          - set_fact:
                                              token: 12345678
                                            run_once: true
                                            delegate_to: "{{ hostvars.localhost.master_node }}"
                                            delegate_facts: true
                                      
                                          - debug:
                                              var: hostvars[hostvars.localhost.master_node].token
                                            when: server_role != 'master'
                                      
                                      PLAY [all] ********************************************************************************************************
                                      
                                      TASK [set_fact] ***************************************************************************************************
                                      skipping: [node1]
                                      ok: [node2 -> localhost]
                                      skipping: [node3]
                                      
                                      TASK [set_fact] ***************************************************************************************************
                                      ok: [node1 -> node2]
                                      
                                      TASK [debug] ******************************************************************************************************
                                      skipping: [node2]
                                      ok: [node1] => 
                                        hostvars[hostvars.localhost.master_node].token: '12345678'
                                      ok: [node3] => 
                                        hostvars[hostvars.localhost.master_node].token: '12345678'
                                      
                                      PLAY RECAP ********************************************************************************************************
                                      node1                      : ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
                                      node2                      : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
                                      node3                      : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
                                      

                                      I compiled R from source and it doesn't find certificates

                                      copy iconCopydownload iconDownload
                                      Warning: unable to access index for repository https://cran.wu.ac.at/src/contrib:
                                        internet routines cannot be loaded
                                      Warning messages:
                                      1: In download.file(url, destfile = f, quiet = TRUE) :
                                        unable to load shared object '/opt/R/4.1.2/lib/R/modules//internet.so':
                                        libcurl-nss.so.4: cannot open shared object file: No such file or directory
                                      2: package ‘remotes’ is not available for this version of R
                                      
                                      A version of this package for your version of R might be available elsewhere,
                                      see the ideas at
                                      https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
                                      
                                      apt purge libcurl4-nss-dev -y
                                      
                                      aptitude install libcurl4-gnutls-dev
                                      
                                      Warning: unable to access index for repository https://cran.wu.ac.at/src/contrib:
                                        internet routines cannot be loaded
                                      Warning messages:
                                      1: In download.file(url, destfile = f, quiet = TRUE) :
                                        unable to load shared object '/opt/R/4.1.2/lib/R/modules//internet.so':
                                        libcurl-nss.so.4: cannot open shared object file: No such file or directory
                                      2: package ‘remotes’ is not available for this version of R
                                      
                                      A version of this package for your version of R might be available elsewhere,
                                      see the ideas at
                                      https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
                                      
                                      apt purge libcurl4-nss-dev -y
                                      
                                      aptitude install libcurl4-gnutls-dev
                                      
                                      Warning: unable to access index for repository https://cran.wu.ac.at/src/contrib:
                                        internet routines cannot be loaded
                                      Warning messages:
                                      1: In download.file(url, destfile = f, quiet = TRUE) :
                                        unable to load shared object '/opt/R/4.1.2/lib/R/modules//internet.so':
                                        libcurl-nss.so.4: cannot open shared object file: No such file or directory
                                      2: package ‘remotes’ is not available for this version of R
                                      
                                      A version of this package for your version of R might be available elsewhere,
                                      see the ideas at
                                      https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
                                      
                                      apt purge libcurl4-nss-dev -y
                                      
                                      aptitude install libcurl4-gnutls-dev
                                      

                                      Add `git remote add usptream` to repositories but using Ansible

                                      copy iconCopydownload iconDownload
                                      - name: Add remote upstream to github projects
                                        # Git module does not know how to add remotes (yet...)
                                        # Using command and silencing corresponding ansible-lint rule 
                                        # noqa command-instead-of-module
                                        command:
                                          cmd: git remote add upstream git@github.com:{{ git_user }}/{{ item }}.git
                                          chdir: /home/user/Documents/github/{{ item }}
                                        register: add_result
                                        changed_when: add_result.rc == 0
                                        failed_when:
                                          - add_result.rc != 0
                                          - add_result.stderr | default('') is not search("remote .* already exists")
                                        loop: "{{ github_repos }}"
                                      

                                      AWX all jobs stop processing and hang indefinitely -- why

                                      copy iconCopydownload iconDownload
                                      def wrap_args_with_ssh_agent(self, args, ssh_key_path, ssh_auth_sock=None, silence_ssh_add=False):
                                          """
                                          Given an existing command line and parameterization this will return the same command line wrapped with the
                                          necessary calls to ``ssh-agent``
                                          """
                                          if ssh_key_path:
                                              ssh_add_command = args2cmdline('ssh-add', ssh_key_path)
                                          ...
                                      
                                      def wrap_args_with_ssh_agent(self, args, ssh_key_path, ssh_auth_sock=None, silence_ssh_add=False):
                                          """
                                          Given an existing command line and parameterization this will return the same command line wrapped with the
                                          necessary calls to ``ssh-agent``
                                          """
                                          if ssh_key_path:
                                              ssh_key_content = ""
                                              with open(ssh_key_path) as f:
                                                  ssh_key_content = f.read()
                                      
                                              ssh_add_command = 'ssh-add - <<< "' + ssh_key_content + '"'
                                      
                                      def wrap_args_with_ssh_agent(self, args, ssh_key_path, ssh_auth_sock=None, silence_ssh_add=False):
                                          """
                                          Given an existing command line and parameterization this will return the same command line wrapped with the
                                          necessary calls to ``ssh-agent``
                                          """
                                          if ssh_key_path:
                                              ssh_add_command = args2cmdline('ssh-add', ssh_key_path)
                                          ...
                                      
                                      def wrap_args_with_ssh_agent(self, args, ssh_key_path, ssh_auth_sock=None, silence_ssh_add=False):
                                          """
                                          Given an existing command line and parameterization this will return the same command line wrapped with the
                                          necessary calls to ``ssh-agent``
                                          """
                                          if ssh_key_path:
                                              ssh_key_content = ""
                                              with open(ssh_key_path) as f:
                                                  ssh_key_content = f.read()
                                      
                                              ssh_add_command = 'ssh-add - <<< "' + ssh_key_content + '"'
                                      

                                      See all related Code Snippets

                                      Community Discussions

                                      Trending Discussions on ansible
                                      • Ansible playbook loop from site yaml or template?
                                      • Line too long: Ansible lint
                                      • Ansible update variable in function
                                      • Can I specify that an argument can't be used with a specific choice in Ansible module spec?
                                      • Ansible: how to achieve idempotence with tasks that append files on host (w/o reverting to initial state)
                                      • Ansible: Show last X output lines
                                      • Ansible, how to set a global fact using roles?
                                      • I compiled R from source and it doesn't find certificates
                                      • Add `git remote add usptream` to repositories but using Ansible
                                      • AWX all jobs stop processing and hang indefinitely -- why
                                      Trending Discussions on ansible

                                      QUESTION

                                      Ansible playbook loop from site yaml or template?

                                      Asked 2022-Apr-01 at 14:16

                                      I'm trying to use my Ansible playbook to call upon a site YAML reference to create a filename that increment for multiple switches. What am I doing wrong? I believe the playbook is pulling from the host YAML?

                                      Format: <switch>-<site>-<floor><stackid>.txt

                                      e.g.: with two switches:

                                      • swi-lon-101.txt
                                      • swi-lon-202.txt

                                      host_vars/host.yaml

                                      project_name: test
                                      device_name: swi
                                      site_abbrev: lon
                                      device_type: switch
                                      switch_stacks:
                                      - id: 01
                                        installation_floor: 1
                                      - id: 02
                                        installation_floor: 2
                                      

                                      templates/switch-template.j2

                                      {% for stack in switch_stacks %}
                                      set system host-name {{ device_name }}-{{ site_abbrev }}-{{ stack.installation_floor }}{{ stack.id }}
                                      {% endfor %}
                                      

                                      The playbook, in which the problem lies, how do I get the hostname to create correctly for each of the 2 switches?

                                      My playbook:

                                      - name: Create Folder Structure
                                        hosts: junos
                                        gather_facts: false
                                      
                                        tasks:
                                          - name: Create Site Specific Folder
                                            file:
                                              path: /home/usr/complete_config/{{ project_name }}
                                              state: directory
                                              mode: 0755
                                      
                                          - name: Set Destination Directory & Filename for Switch Configurations
                                            set_fact:
                                              dest_dir: /home/usr/complete_config/{{ project_name }}
                                              full_device_name: "{{ device_name|lower }}-{{ site_abbrev|lower }}-{{ switch_stacks.installation_floor }}{{ switch_stacks.id }}.txt"
                                            when: device_type == 'switch'
                                      

                                      Ansible error, running:

                                      ansible-playbook playbooks/site-playbook.yaml
                                      
                                      TASK [Set Destination Directory & Filename for Switch Configurations] **************************************************
                                      fatal: [site-switch]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'list object' has no attribute 'installation_floor'\n\nThe error appears to be in '/home/usr/playbooks/switch-playbook.yaml': line 19, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: Set Destination Directory & Filename for Switch Configurations\n      ^ here\n"}
                                      

                                      ANSWER

                                      Answered 2022-Mar-31 at 18:39

                                      So, you do need a loop in order to set this fact, otherwise, you are trying to access a installation_floor on a list, which cannot be.

                                      You will also face an issue with the id of your items in switch_stacks, as 01 is an int and will end up displayed as 1, simply. So you either need to declare those as string, or to pad them with a format filter.

                                      So, you end up with this task:

                                      - set_fact:
                                          full_device_name: >-
                                            {{ 
                                              full_device_name 
                                              | default([]) 
                                              + [
                                                device_name | lower ~ '-' ~ 
                                                site_abbrev | lower ~ '-' ~ 
                                                item.installation_floor  ~  
                                                "%02d" | format(item.id) ~ '.txt'
                                              ]
                                            }}
                                        loop: "{{ switch_stacks }}"
                                        when: device_type == 'switch'
                                      

                                      Which will create a list:

                                      full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      

                                      Given the playbook:

                                      - hosts: localhost
                                        gather_facts: false
                                      
                                        tasks:
                                          - set_fact:
                                              full_device_name: >-
                                                {{ 
                                                  full_device_name 
                                                  | default([]) 
                                                  + [
                                                    device_name | lower ~ '-' ~ 
                                                    site_abbrev | lower ~ '-' ~ 
                                                    item.installation_floor  ~  
                                                    "%02d" | format(item.id) ~ '.txt'
                                                  ]
                                                }}
                                            loop: "{{ switch_stacks }}"
                                            when: device_type == 'switch'
                                            vars:
                                              device_name: swi
                                              site_abbrev: lon
                                              device_type: switch
                                              switch_stacks:
                                                - id: 01
                                                  installation_floor: 1
                                                - id: 02
                                                  installation_floor: 2
                                      
                                          - debug: 
                                              var: full_device_name
                                      

                                      This yields:

                                      TASK [set_fact] ************************************************************
                                      ok: [localhost] => (item={'id': 1, 'installation_floor': 1})
                                      ok: [localhost] => (item={'id': 2, 'installation_floor': 2})
                                      
                                      TASK [debug] ***************************************************************
                                      ok: [localhost] => 
                                        full_device_name:
                                        - swi-lon-101.txt
                                        - swi-lon-202.txt
                                      

                                      Source https://stackoverflow.com/questions/71696913

                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                      Vulnerabilities

                                      A flaw was found in the solaris_zone module from the Ansible Community modules. When setting the name for the zone on the Solaris host, the zone name is checked by listing the process with the 'ps' bare command on the remote machine. An attacker could take advantage of this flaw by crafting the name of the zone and executing arbitrary commands in the remote host. Ansible Engine 2.7.15, 2.8.7, and 2.9.2 as well as previous versions are affected.
                                      A flaw was discovered in the way Ansible templating was implemented in versions before 2.6.18, 2.7.12 and 2.8.2, causing the possibility of information disclosure through unexpected variable substitution. By taking advantage of unintended variable substitution the content of any variable may be disclosed.
                                      ansible before versions 2.8.6, 2.7.14, 2.6.20 is vulnerable to a None

                                      Install ansible

                                      You can install using 'pip install ansible' or download it from GitHub, PyPI.
                                      You can use ansible like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

                                      Support

                                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                                      DOWNLOAD this Library from

                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                                      over 430 million Knowledge Items
                                      Find more libraries
                                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                                      Explore Kits

                                      Save this library and start creating your kit

                                      Explore Related Topics

                                      Share this Page

                                      share link
                                      Reuse Pre-built Kits with ansible
                                      Consider Popular DevOps Libraries
                                      Try Top Libraries by ansible
                                      Compare DevOps Libraries with Highest Support
                                      Compare DevOps Libraries with Highest Quality
                                      Compare DevOps Libraries with Highest Security
                                      Compare DevOps Libraries with Permissive License
                                      Compare DevOps Libraries with Highest Reuse
                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                                      over 430 million Knowledge Items
                                      Find more libraries
                                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                                      Explore Kits

                                      Save this library and start creating your kit

                                      • © 2022 Open Weaver Inc.