Hi Claudia de Luna,
thank you for your response.
*following your **instruction i tried to collect the host name using **regular
**expression used by peter and i can collect ios version.*
*another question is triggered here after looking on your playbook**:-*
register: facts_output
- debug: var=facts_output
- debug: var=facts_output.ansible_facts.ansible_net_version
question is regarding last line here, in your last line you add
ansible_facts, can you please let me know what is purpose of this and where
it came. rest i know about ansible_net_version.
also can you please refer me any document how to use regular expression
ansible playbook.i have used these in python so i have small understanding
in python.
Regards,
*Surjeet Singh*
Technical Specialist – Networks DATA
CCNA, CCNP(R&S)
Cell : +917838707047
To become bigger person,need to walk with bigger Vision !!!!
On Sun, Jan 21, 2018 at 11:59 PM, Claudia de Luna <[email protected]> wrote:
> Using Ansible ios_facts module
>
> Here is a simple playbook to gather ios facts.
>
> I took the output and pasted it into one of the may JSON lint/editors on
> line to easily see the structure and then added a debug statement for the
> key:value pair I wanted. Version in this case.
>
>
> ---
> - hosts: cisco
> connection: local
> gather_facts: False
> ignore_errors: yes
>
>
> vars:
> cli:
> host: "{{ host }}"
> username: "{{ username }}"
> password: "{{ password }}"
>
>
> tasks:
> - name: Gather NX-OS Facts
> ios_facts:
> provider: "{{ cli }}"
>
>
> register: facts_output
>
>
> - debug: var=facts_output
> - debug: var=facts_output.ansible_facts.ansible_net_version
>
>
> - local_action: copy content="{{ facts_output }}" dest="./{{
> inventory_hostname }}.txt"
>
>
>
>
>
>
>
> TASK [debug] ************************************************************
> ************************************************************
> ********************************
> ok: [arctic-3650] => {
> "facts_output.ansible_facts.ansible_net_version": "03.06.06E"
> }
>
>
>
>
>
>
> On Saturday, January 20, 2018 at 8:57:38 AM UTC-8, Surjeet Singh wrote:
>>
>> Hi Peter,
>>
>> I am facing another issue with same i am trying to debug version only
>> from the results of show version using below method but it gives me
>> variable error. however when i run playbook -vvv i can see the show version
>> command is excuted and they are mapped to stdout and stdout_lines as you
>> mention in document. can you please help me with that or redirect me
>> towards of link.
>>
>> register: version
>> - debug: var = version.stdout[0].Version
>>
>> Regards/surjeet
>>
>> On Saturday, September 3, 2016 at 8:58:39 AM UTC+5:30, Peter Sprygada
>> wrote:
>>>
>>> Hi Valerie,
>>>
>>> Since network devices such as IOS do not provide a shell environment nor
>>> the ability to download and run arbitrary executables, we are fairly
>>> constrained from using the current connection plugin module implemented in
>>> core. So in order to build modules that work with network devices, we
>>> build an integration that effectively treats SSH or more appropriately
>>> said, CLI over SSH like an API. During module execute, we build an SSH
>>> session to the remote device for the purposes of sending and receiving
>>> commands and output. That is way we must specify connection=local.
>>>
>>> Peter
>>>
>>> On Fri, Sep 2, 2016 at 7:55 AM, Valérie P <[email protected]> wrote:
>>>
>>>> Hello John,
>>>>
>>>> I've had a little bit of trouble with the ios_* modules and thanks to
>>>> the source found in this sample it is now functional, anyhow I do not
>>>> understand every line of it, and particularly the "connection: local" one.
>>>> What is it used for? The ansible documentation refer to the connection:
>>>> local as a way to make the playbook play locally.
>>>>
>>>> "It may be useful to use a playbook locally, rather than by connecting
>>>> over SSH. This can be useful for assuring the configuration of a system by
>>>> putting a playbook in a crontab. This may also be used to run a playbook
>>>> inside an OS installer, such as an Anaconda kickstart.
>>>>
>>>> To run an entire playbook locally, just set the “hosts:” line to
>>>> “hosts: 127.0.0.1” and then run the playbook like so:
>>>>
>>>> ansible-playbook playbook.yml --connection=local
>>>>
>>>> Alternatively, a local connection can be used in a single playbook
>>>> play, even if other plays in the playbook use the default remote connection
>>>> type:
>>>>
>>>> - hosts: 127.0.0.1
>>>> connection: local
>>>>
>>>> "
>>>> Why is the connection: local parameters a must for it to work?
>>>>
>>>> Thanks in advance!
>>>> Valerie
>>>>
>>>>
>>>> Le mercredi 24 août 2016 09:20:15 UTC+2, John Barker a écrit :
>>>>>
>>>>> I've added a comment with the the corrected playbook sample
>>>>>
>>>>> https://gist.github.com/privateip/11b042e569585ee9248a
>>>>>
>>>>> Regards,
>>>>> John Barker
>>>>>
>>>>> On Wednesday, 10 August 2016 15:32:23 UTC+1, Bharath Bharadwaj wrote:
>>>>>>
>>>>>> Hi All,
>>>>>>
>>>>>> I'm new to Ansible and yml, my goal is to automate a part of network
>>>>>> operation, I just want to start with a very simple output, copied below
>>>>>> is
>>>>>> my playbook, I'm trying to run a show version, but i'm getting error when
>>>>>> executing the output, yet when i try the same yml script through yml
>>>>>> validator, there is no errors.
>>>>>>
>>>>>> My Playbook
>>>>>>
>>>>>> vars:
>>>>>> cli:
>>>>>> host: "{{ network }}"
>>>>>> username: admin
>>>>>> password: test@123
>>>>>> transport: cli
>>>>>>
>>>>>> tasks:
>>>>>> - name: run multiple commands on remote nodes
>>>>>> ios_command:
>>>>>> - commands: show version
>>>>>> - provider: "{{ cli }}"
>>>>>> - transport: cli
>>>>>>
>>>>>> Error:
>>>>>> "ERROR! playbooks must be a list of plays
>>>>>>
>>>>>> The error appears to have been in '/etc/ansible/playbooks/cisco_ios.yml':
>>>>>> line 1, column 1, but may
>>>>>> be elsewhere in the file depending on the exact syntax problem.
>>>>>>
>>>>>> The offending line appears to be:
>>>>>>
>>>>>>
>>>>>> vars:
>>>>>> ^ here"
>>>>>>
>>>>> --
>>>> 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 post to this group, send email to [email protected].
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/ansible-project/6383da04-b68b-4a33-85e9-87318eb0a5b8%
>>>> 40googlegroups.com
>>>> <https://groups.google.com/d/msgid/ansible-project/6383da04-b68b-4a33-85e9-87318eb0a5b8%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
> 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/Ul5D-gAzRrg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ansible-project/826a69bb-d730-48f6-a7ce-103808c1f0f0%40googlegroups.
> com
> <https://groups.google.com/d/msgid/ansible-project/826a69bb-d730-48f6-a7ce-103808c1f0f0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CA%2BpLPDTaTE0o3NWOp00je5ZiRTMveL4z3MTTPuiU6%2Bemv6v6%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.