[ncontu@cmd-config cmd]$ ansible-playbook playbooks/test.yml -e
"variable_host=127.0.0.1"
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to
allow bad characters in group names by default, this will change, but still
be user configurable on
 deprecation. This feature will be removed in version 2.10. Deprecation
warnings can be disabled by setting deprecation_warnings=False in
ansible.cfg.
 [WARNING]: Invalid characters were found in group names but not replaced,
use -vvvv to see details


PLAY [127.0.0.1]
***************************************************************************************************************************************************************

TASK [Gathering Facts]
*********************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [Get PHP version from site]
***********************************************************************************************************************************************
ok: [127.0.0.1]

TASK [Show PHP version from site]
**********************************************************************************************************************************************
ok: [127.0.0.1] => {
    "PHP_SITE_RESPONSE": {
        "cache_control": "max-age=0",
        "changed": false,
        "connection": "close",
        "content":
"{\"announcement\":true,\"tags\":[\"security\"],\"date\":\"19 Mar
2020\",\"source\":[{\"filename\":\"php-7.2.29.tar.bz2\",\"name\":\"PHP
7.2.29
(tar.bz2)\",\"sha256\":\"eaa1f5503f2bf0c8569ec4ae80ffd8ca8cbc260f01c2503dd0e83dfc9cf0b923\",\"date\":\"19
Mar 2020\"},{\"filename\":\"php-7.2.29.tar.gz\",\"name\":\"PHP 7.2.29
(tar.gz)\",\"sha256\":\"ea5c96309394a03a38828cc182058be0c09dde1f00f35809622c2d05c50ee890\",\"date\":\"19
Mar 2020\"},{\"filename\":\"php-7.2.29.tar.xz\",\"name\":\"PHP 7.2.29
(tar.xz)\",\"sha256\":\"b117de74136bf4b439d663be9cf0c8e06a260c1f340f6b75ccadb609153a7fe8\",\"date\":\"19
Mar 2020\"}],\"version\":\"7.2.29\"}",
        "content_language": "en",
        "content_type": "application/json",
        "cookies": {
            "COUNTRY": "NA%2C208.77.65.47"
        },
        "cookies_string": "COUNTRY=NA%2C208.77.65.47",
        "date": "Fri, 10 Apr 2020 18:05:04 GMT",
        "elapsed": 0,
        "etag": "\"myra-2a0383c2\"",
        "expires": "Fri, 10 Apr 2020 18:05:04 GMT",
        "failed": false,
        "json": {
            "announcement": true,
            "date": "19 Mar 2020",
            "source": [
                {
                    "date": "19 Mar 2020",
                    "filename": "php-7.2.29.tar.bz2",
                    "name": "PHP 7.2.29 (tar.bz2)",
                    "sha256":
"eaa1f5503f2bf0c8569ec4ae80ffd8ca8cbc260f01c2503dd0e83dfc9cf0b923"
                },
                {
                    "date": "19 Mar 2020",
                    "filename": "php-7.2.29.tar.gz",
                    "name": "PHP 7.2.29 (tar.gz)",
                    "sha256":
"ea5c96309394a03a38828cc182058be0c09dde1f00f35809622c2d05c50ee890"
                },
                {
                    "date": "19 Mar 2020",
                    "filename": "php-7.2.29.tar.xz",
                    "name": "PHP 7.2.29 (tar.xz)",
                    "sha256":
"b117de74136bf4b439d663be9cf0c8e06a260c1f340f6b75ccadb609153a7fe8"
                }
            ],
            "tags": [
                "security"
            ],
            "version": "7.2.29"
        },
        "msg": "OK (unknown bytes)",
        "redirected": false,
        "server": "myracloud",
        "set_cookie": "COUNTRY=NA%2C208.77.65.47; expires=Fri, 17-Apr-2020
18:05:04 GMT; Max-Age=604800; path=/; domain=.php.net",
        "status": 200,
        "transfer_encoding": "chunked",
        "url": "https://www.php.net/releases/?json&version=7.2";,
        "x_frame_options": "SAMEORIGIN"
    }
}

PLAY RECAP
*********************************************************************************************************************************************************************
127.0.0.1                  : ok=3    changed=0    unreachable=0    failed=0
   skipped=0    rescued=0    ignored=0

Il giorno ven 10 apr 2020 alle ore 19:38 Dan Linder <[email protected]> ha
scritto:

> Hi Nicola,
>
> I'd take a bit step back and reduce your playbook to just a couple of
> tasks:
>
> ```
> - hosts: "{{ variable_host }}"
>   serial: 1
>   tasks:
>     -
>       name: "Get PHP version from site"
>       register: PHP_SITE_RESPONSE
>       uri:
>         body_format: json
>         method: GET
>         return_content: true
>         url: "https://www.php.net/releases/?json&version=7.2";
>       run_once: true
>       delegate_to: 127.0.0.1
>
>     -
>       name: "Show PHP version from site"
>       debug:
>         var: PHP_SITE_RESPONSE
> ```
>
> What output does that produce?
>
> DanL
>
> On Friday, April 10, 2020 at 8:48:06 AM UTC-5, Nicola Contu wrote:
>>
>> Hello,
>> I am trying to get the latest version of few softwares and comparing it
>> with a list of hosts with the current installed.
>>
>> Calling the github API is creating issues with the number of call due to
>> the the list of hosts that is quite big.
>> So I would like to register the latest versions in a variable and then
>> use it to compare for each host.
>>
>>  I tried a lot of things, like run_once, changed_when but it seems like
>> it is not working.
>>
>> Here is the playbook.
>>
>> - hosts: "{{ variable_host }}"
>>   serial: 1
>>   tasks:
>>     -
>>       name: "Get PHP version from site"
>>       register: PHP_SITE_RESPONSE
>>       uri:
>>         body_format: json
>>         method: GET
>>         return_content: true
>>         url: "https://www.php.net/releases/?json&version=7.2";
>>       run_once: true
>>       delegate_to: 127.0.0.1
>>
>>     -
>>       name: "Get APACHE version from site"
>>       shell: "curl -s '
>> https://api.github.com/repos/apache/httpd/tags?per_page=100' | jq -r
>> '.[] | .name' | sort -V | grep ^2.4 | tail -n 1"
>>       run_once: true
>>       register: HTTPD_SITE_VERSION
>>       delegate_to: 127.0.0.1
>>
>>     -
>>       name: "Get GIT version from site"
>>       shell: "curl -s '
>> https://api.github.com/repos/git/git/tags?per_page=100' | jq -r '.[] |
>> .name' | sort -V | grep ^v2 | tail -n 1 | cut -f1 -d'-' | tail -
>>       run_once: true
>>       register: GIT_SITE_VERSION
>>       delegate_to: 127.0.0.1
>>
>>     -
>>       name: "Get current version PHP"
>>       register: CURRENT_PHP_VERSION
>>       shell: "/usr/local/php/bin/php --version | head -c 10 | tail -c 6"
>>
>>     -
>>       name: "Get current version PHP"
>>       register: CURRENT_HTTPD_VERSION
>>       shell: "httpd -v | grep 2.4 | tail -n 1 | tail -c 14 | head -c 6"
>>     -
>>       name: "Get current version PHP"
>>       register: CURRENT_GIT_VERSION
>>       shell: "git --version | tail -c 7"
>>
>>     - name: Write header
>>       run_once: true
>>       lineinfile: dest=/home/ncontu/test.txt create=yes line="LATEST
>> VERSION PHP {{PHP_SITE_RESPONSE.json.version}} HTTPD
>> {{HTTPD_SITE_VERSION.stdout_lines[0]VERSION.stdout_lines[0]}}"
>>       delegate_to: 127.0.0.1
>>
>>     - name: Write to local disk
>>       lineinfile: dest=/home/ncontu/test.txt insertafter=EOF create=yes
>> line="{{ ansible_fqdn }} {{CURRENT_PHP_VERSION.stdout_lines[0]}}
>> {{CURRENT_HTTPD_VERSI}} {{CURRENT_GIT_VERSION.stdout_lines[0]}}"
>>       delegate_to: 127.0.0.1
>>       when: CURRENT_PHP_VERSION.stdout_lines[0] !=
>> PHP_SITE_RESPONSE.json.version or CURRENT_HTTPD_VERSION.stdout_lines[0] !=
>> HTTPD_SITE_VERSION.stdout_lines[VERSION.stdout_lines[0] !=
>> GIT_SITE_VERSION.stdout_lines[0]
>>
>>     - name: Cat produced file
>>       command: /bin/cat /home/ncontu/test.txt
>>       register: details
>>       delegate_to: 127.0.0.1
>>       run_once: true
>>       when: inventory_hostname == ansible_play_hosts_all[-1]
>>
>>     - name: Base64 produced file
>>       command: base64 /home/ncontu/test.txt
>>       register: basefile
>>       delegate_to: 127.0.0.1
>>       run_once: true
>>       when: inventory_hostname == ansible_play_hosts_all[-1]
>>
>>
>> Any help would be much appreciated.
>>
>> Thanks
>>
>
>
> On Friday, April 10, 2020 at 11:01:23 AM UTC-5, Nicola Contu wrote:
>>
>> Hey Dick,
>> I tried that but the subsequent play is not able to recognise those
>> variables.
>>
>>
>> *{"msg": "The task includes an option with an undefined variable. The
>> error was: 'PHP_SITE_RESPONSE' is undefined*
>>
>>
>> I changed the playbook like this :
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *- hosts: 127.0.0.1  tasks:    - name: "Get PHP version from site"
>> register: PHP_SITE_RESPONSE      uri:        body_format: json
>> method: GET        return_content: true        url:
>> "https://www.php.net/releases/?json&version=7.2
>> <https://www.php.net/releases/?json&version=7.2>"    - name: "Get APACHE
>> version from site"      shell: "curl -s
>> 'https://api.github.com/repos/apache/httpd/tags?per_page=100
>> <https://api.github.com/repos/apache/httpd/tags?per_page=100>' | jq -r '.[]
>> | .name' | sort -V | grep ^2.4 | tail -n 1"      register:
>> HTTPD_SITE_VERSION    - name: "Get GIT version from site"      shell: "curl
>> -s 'https://api.github.com/repos/git/git/tags?per_page=100
>> <https://api.github.com/repos/git/git/tags?per_page=100>' | jq -r '.[] |
>> .name' | sort -V | grep ^v2 | tail -n 1 | cut -f1 -d'-' | tail -c 7"
>> register: GIT_SITE_VERSION- hosts: dev preprod  serial: 1  tasks:    -
>> name: "Get current version PHP"      register: CURRENT_PHP_VERSION
>> shell: "/usr/local/php/bin/php --version | head -c 10 | tail -c 6"    -
>> name: "Get current version HTTPD"      register: CURRENT_HTTPD_VERSION
>> shell: "httpd -v | grep 2.4 | tail -n 1 | tail -c 14 | head -c 6"    -
>> name: "Get current version GIT"      register: CURRENT_GIT_VERSION
>> shell: "git --version | tail -c 7"    - name: Write header      run_once:
>> true      lineinfile: dest=/home/ncontu/test.txt create=yes line="LATEST
>> VERSION PHP {{PHP_SITE_RESPONSE.json.version}} HTTPD
>> {{HTTPD_SITE_VERSION.stdout_lines[0]}} GIT
>> {{GIT_SITE_VERSION.stdout_lines[0]}}"      delegate_to: 127.0.0.1    -
>> name: Write to local disk      lineinfile: dest=/home/ncontu/test.txt
>> insertafter=EOF create=yes line="{{ ansible_fqdn }}
>> {{CURRENT_PHP_VERSION.stdout_lines[0]}}
>> {{CURRENT_HTTPD_VERSION.stdout_lines[0]}}
>> {{CURRENT_GIT_VERSION.stdout_lines[0]}}"      delegate_to: 127.0.0.1
>> when: CURRENT_PHP_VERSION.stdout_lines[0] != PHP_SITE_RESPONSE.json.version
>> or CURRENT_HTTPD_VERSION.stdout_lines[0] !=
>> HTTPD_SITE_VERSION.stdout_lines[0] or CURRENT_GIT_VERSION.stdout_lines[0]
>> != GIT_SITE_VERSION.stdout_lines[0]*
>>
>> *.*
>> *.*
>> *.*
>> *.*
>> *.*
>>
>> Is there a way to tell those variables are from another play?
>> Or am I doing something wrong?
>>
>> Thanks a lot for your help.
>>
>> Il giorno ven 10 apr 2020 alle ore 16:32 Dick Visser <[email protected]>
>> ha scritto:
>>
>>> Add a new play to the top of the list that targets localhost.
>>> The use the registered vars in a subsequent play that targets all your
>>> hosts.
>>>
>>> On Fri, 10 Apr 2020 at 15:48, Nicola Contu <[email protected]> wrote:
>>>
>>>> Hello,
>>>> I am trying to get the latest version of few softwares and comparing it
>>>> with a list of hosts with the current installed.
>>>>
>>>> Calling the github API is creating issues with the number of call due
>>>> to the the list of hosts that is quite big.
>>>> So I would like to register the latest versions in a variable and then
>>>> use it to compare for each host.
>>>>
>>>>  I tried a lot of things, like run_once, changed_when but it seems like
>>>> it is not working.
>>>>
>>>> Here is the playbook.
>>>>
>>>> - hosts: "{{ variable_host }}"
>>>>   serial: 1
>>>>   tasks:
>>>>     -
>>>>       name: "Get PHP version from site"
>>>>       register: PHP_SITE_RESPONSE
>>>>       uri:
>>>>         body_format: json
>>>>         method: GET
>>>>         return_content: true
>>>>         url: "https://www.php.net/releases/?json&version=7.2";
>>>>       run_once: true
>>>>       delegate_to: 127.0.0.1
>>>>
>>>>     -
>>>>       name: "Get APACHE version from site"
>>>>       shell: "curl -s '
>>>> https://api.github.com/repos/apache/httpd/tags?per_page=100' | jq -r
>>>> '.[] | .name' | sort -V | grep ^2.4 | tail -n 1"
>>>>       run_once: true
>>>>       register: HTTPD_SITE_VERSION
>>>>       delegate_to: 127.0.0.1
>>>>
>>>>     -
>>>>       name: "Get GIT version from site"
>>>>       shell: "curl -s '
>>>> https://api.github.com/repos/git/git/tags?per_page=100' | jq -r '.[] |
>>>> .name' | sort -V | grep ^v2 | tail -n 1 | cut -f1 -d'-' | tail -
>>>>       run_once: true
>>>>       register: GIT_SITE_VERSION
>>>>       delegate_to: 127.0.0.1
>>>>
>>>>     -
>>>>       name: "Get current version PHP"
>>>>       register: CURRENT_PHP_VERSION
>>>>       shell: "/usr/local/php/bin/php --version | head -c 10 | tail -c 6"
>>>>
>>>>     -
>>>>       name: "Get current version PHP"
>>>>       register: CURRENT_HTTPD_VERSION
>>>>       shell: "httpd -v | grep 2.4 | tail -n 1 | tail -c 14 | head -c 6"
>>>>     -
>>>>       name: "Get current version PHP"
>>>>       register: CURRENT_GIT_VERSION
>>>>       shell: "git --version | tail -c 7"
>>>>
>>>>     - name: Write header
>>>>       run_once: true
>>>>       lineinfile: dest=/home/ncontu/test.txt create=yes line="LATEST
>>>> VERSION PHP {{PHP_SITE_RESPONSE.json.version}} HTTPD
>>>> {{HTTPD_SITE_VERSION.stdout_lines[0]VERSION.stdout_lines[0]}}"
>>>>       delegate_to: 127.0.0.1
>>>>
>>>>     - name: Write to local disk
>>>>       lineinfile: dest=/home/ncontu/test.txt insertafter=EOF create=yes
>>>> line="{{ ansible_fqdn }} {{CURRENT_PHP_VERSION.stdout_lines[0]}}
>>>> {{CURRENT_HTTPD_VERSI}} {{CURRENT_GIT_VERSION.stdout_lines[0]}}"
>>>>       delegate_to: 127.0.0.1
>>>>       when: CURRENT_PHP_VERSION.stdout_lines[0] !=
>>>> PHP_SITE_RESPONSE.json.version or CURRENT_HTTPD_VERSION.stdout_lines[0] !=
>>>> HTTPD_SITE_VERSION.stdout_lines[VERSION.stdout_lines[0] !=
>>>> GIT_SITE_VERSION.stdout_lines[0]
>>>>
>>>>     - name: Cat produced file
>>>>       command: /bin/cat /home/ncontu/test.txt
>>>>       register: details
>>>>       delegate_to: 127.0.0.1
>>>>       run_once: true
>>>>       when: inventory_hostname == ansible_play_hosts_all[-1]
>>>>
>>>>     - name: Base64 produced file
>>>>       command: base64 /home/ncontu/test.txt
>>>>       register: basefile
>>>>       delegate_to: 127.0.0.1
>>>>       run_once: true
>>>>       when: inventory_hostname == ansible_play_hosts_all[-1]
>>>>
>>>>
>>>> Any help would be much appreciated.
>>>>
>>>> Thanks
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Ansible Project" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/ansible-project/5b4d3382-6545-4213-a915-ea8f6e3d85b5%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/ansible-project/5b4d3382-6545-4213-a915-ea8f6e3d85b5%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> Sent from a mobile device - please excuse the brevity, spelling and
>>> punctuation.
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Ansible Project" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/ansible-project/YAiOo8cTtis/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/CAL8fbwPDaWvADiUa8r%2BN2kqYwa4md2QusnVv7kPv_bWSU_b5Ew%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwPDaWvADiUa8r%2BN2kqYwa4md2QusnVv7kPv_bWSU_b5Ew%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/YAiOo8cTtis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7e4959e3-498f-4929-a1d5-2e1c4f3dfa40%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7e4959e3-498f-4929-a1d5-2e1c4f3dfa40%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAMTZZh38FEHU4L0zRtMO7sCLdPo-S5cNo0XyLeiQPQPJSCvFCA%40mail.gmail.com.

Reply via email to