[ansible-project] Switch config template

2018-02-06 Thread Surjeet Singh
Hi All,

I am working to prepare config template for one of my on going project, 
where i have four type of devices to create template and push the config. i 
have made my strategy to how to deal with this.

now i want write my play book to check condition under the device_type  
variable and create config accordingly to device type let's say if it is 
core get the veritable from multiple dict(l2vlan,l3vlan,core_interfaces), 
same for access and others.

so my question,  is there any way to match variable. also tell the play 
book to look on multiple dict ?

regards/Surjeet 

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2f3628bf-5b5f-4757-93c9-63960a142149%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Simple cisco IOS show version

2018-01-30 Thread Surjeet Singh
Hi,

I would like to share that i managed to collect inventory information with
only minor changes in ansible playbook.

sharing just to help other people who new learner like me.

# write facts in inventory
- name: write the inventory in into file
  copy:
content: |
  MGMT_IP;HOSTNAME;MODEL;VERSION;IMAGE;
  {% for host in ansible_play_hosts %}
  {{ hostvars[host].inventory_hostname}};{{
hostvars[host].facts_output.ansible_facts.ansible_net_hostname }};{{
hostvars[host].facts_output.ansible_facts.ansible_net_model }};{{
hostvars[host].facts_output.ansible_facts.ansible_net_version }};{{
hostvars[host].facts_output.ansible_facts.ansible_net_image }}
  {% endfor %}

dest: /etc/ansible/facts/systems.csv
backup: yes

output will look like below after minor changes in excel.

MGMT_IP HOSTNAME MODEL VERSION IMAGE
1.1.1.1 R1 3725 (R7000) processor 12.4(15)T14 tftp://255.255.255.255/unknown
2.2.2.2 R2 3725 (R7000) processor 12.4(15)T14 tftp://255.255.255.255/unknown
3.3.3.3 R3 3725 (R7000) processor 12.4(15)T14 tftp://255.255.255.255/unknown
4.4.4.4 R4 3725 (R7000) processor 12.4(15)T14 tftp://255.255.255.255/unknown
5.5.5.5 router_r5 3725 (R7000) processor 12.4(15)T14 tftp://
255.255.255.255/unknown
6.6.6.6 R6 3725 (R7000) processor 12.4(15)T14 tftp://255.255.255.255/unknown
7.7.7.7 R7 3725 (R7000) processor 12.4(15)T14 tftp://255.255.255.255/unknown
8.8.8.8 router_r8 3725 (R7000) processor 12.4(15)T14 tftp://
255.255.255.255/unknown

Regards,
*Surjeet Singh*
Technical Specialist – Networks DATA
CCNA, CCNP(R)
Cell : +917838707047

To become bigger person,need to walk with bigger Vision 

On Mon, Jan 29, 2018 at 10:16 AM, Surjeet Singh <surjeet.singh0...@gmail.com
> wrote:

> Thank you for your response.
>
> I also managed to fix this by modifying my code little bit
> .I will share my updated code with you..
>
> Regards/Surjeet
>
> On 29-Jan-2018 2:51 AM, "Claudia de Luna" <delu...@gmail.com> wrote:
>
>> Hi Surjeet,
>>
>> I have a script that is very similar to yours.  I pass it either a file
>> or a path to a directory full of individual files per device with all the
>> show command output.
>>
>> I take the output of each file and append it to a list, fsm_all_results.
>> Once done processing either one file or a directory full of files, i save
>> fsm_all_results to a CSV file.
>>
>> Hope this helps!
>>
>> Good luck.
>>
>> # Make sure we have files to process (at least 1)
>> if len(file_list) > 0:
>>
>> # Open the CSV file to store results
>> csv_results_fh = open_file(results_dir, 'wb')
>> csv_writer = csv.writer(csv_results_fh, quoting=csv.QUOTE_MINIMAL)
>>
>> # Iterate through the valid file list. If the script was passed a 
>> filename it will be a file_list of 1
>> # If the script was passed a directory it will be a list of files with a 
>> valid extension
>> for fil in file_list:
>>
>> print("Processing device file: " + fil)
>>
>> # open_file function returns a file handle
>> fh = open_file(fil, 'r')
>>
>> # Read the file contents into a variable for parsing
>> file_contents = fh.read()
>> # Close file
>> fh.close()
>>
>> # Send TextFSM Template name and data to parse to text_fsm_parsing 
>> function
>> # file_results returns the parsed results and table returns the 
>> header
>> fil_results, table = text_fsm_parse(textfsm_template, file_contents)
>> print("file results of lenght {} from 
>> text_fsm_parse:\n{}".format(str(len(fil_results)),fil_results[1]))
>>
>> # Append fil_results list of results to list of all results
>> fsm_all_results.append(fil_results)
>>
>> # Keep track of files without parser output in the no_output list so 
>> it can be printed later
>> if len(fil_results) == 0:
>> no_output.append(fil)
>>
>>
>>
>> # Write the header row in the CSV file
>> if table:
>>     csv_writer.writerow(table.header)
>> else:
>> sys.exit("Parsing Error. Execution aborted.")
>>
>> # Write each row in the fsm_all_results list to the CSV file
>> for re_row in fsm_all_results:
>> for single_row in re_row:
>> csv_writer.writerow(single_row)
>> # print(single_row)
>>
>>
>>
>>
>>
>>
>>
>>
>> On Saturday, January 27, 2018 at 6:29:25 AM UTC-8, Surjeet Singh wrote:
>>>
>>> Hi Claudia,
>&g

Re: [ansible-project] Re: Simple cisco IOS show version

2018-01-28 Thread Surjeet Singh
Thank you for your response.

I also managed to fix this by modifying my code little bit
.I will share my updated code with you..

Regards/Surjeet

On 29-Jan-2018 2:51 AM, "Claudia de Luna" <delu...@gmail.com> wrote:

> Hi Surjeet,
>
> I have a script that is very similar to yours.  I pass it either a file or
> a path to a directory full of individual files per device with all the show
> command output.
>
> I take the output of each file and append it to a list, fsm_all_results.
> Once done processing either one file or a directory full of files, i save
> fsm_all_results to a CSV file.
>
> Hope this helps!
>
> Good luck.
>
> # Make sure we have files to process (at least 1)
> if len(file_list) > 0:
>
> # Open the CSV file to store results
> csv_results_fh = open_file(results_dir, 'wb')
> csv_writer = csv.writer(csv_results_fh, quoting=csv.QUOTE_MINIMAL)
>
> # Iterate through the valid file list. If the script was passed a 
> filename it will be a file_list of 1
> # If the script was passed a directory it will be a list of files with a 
> valid extension
> for fil in file_list:
>
> print("Processing device file: " + fil)
>
> # open_file function returns a file handle
> fh = open_file(fil, 'r')
>
> # Read the file contents into a variable for parsing
> file_contents = fh.read()
> # Close file
> fh.close()
>
> # Send TextFSM Template name and data to parse to text_fsm_parsing 
> function
> # file_results returns the parsed results and table returns the header
> fil_results, table = text_fsm_parse(textfsm_template, file_contents)
> print("file results of lenght {} from 
> text_fsm_parse:\n{}".format(str(len(fil_results)),fil_results[1]))
>
> # Append fil_results list of results to list of all results
> fsm_all_results.append(fil_results)
>
> # Keep track of files without parser output in the no_output list so 
> it can be printed later
> if len(fil_results) == 0:
> no_output.append(fil)
>
>
>
> # Write the header row in the CSV file
> if table:
> csv_writer.writerow(table.header)
> else:
> sys.exit("Parsing Error. Execution aborted.")
>
> # Write each row in the fsm_all_results list to the CSV file
> for re_row in fsm_all_results:
> for single_row in re_row:
> csv_writer.writerow(single_row)
> # print(single_row)
>
>
>
>
>
>
>
>
> On Saturday, January 27, 2018 at 6:29:25 AM UTC-8, Surjeet Singh wrote:
>>
>> Hi Claudia,
>>
>> i am strugling with with issue in putting textfsm in loop. i can read all
>> my file end with .txt but i have issue in moving for loop so i can run
>> textfsml on all files instead of last file.
>>
>> can you please help me with that.
>>
>> import jtextfsm as textfsm
>> import glob, os
>>
>> os.chdir("/etc/ansible/facts/")
>> for file in glob.glob("*_iosfacts.txt"):
>> input_file = open(file)
>> raw_text_data = input_file.read()
>> input_file.close()
>>
>> # Run the text through the FSM.
>> # The argument 'template' is a file handle and 'raw_text_data' is a
>> # string with the content from the show_inventory.txt file
>> template = open("/etc/ansible/parse-inventory-with-textfsm/show_invento
>> ry_multiple.textfsm")
>> re_table = textfsm.TextFSM(template)
>> fsm_results = re_table.ParseText( raw_text_data)
>>
>> # the results are written to a CSV file
>> outfile_name = open("/etc/ansible/parse-inventory-with-textfsm//outfile.csv",
>> "w+")
>> outfile = outfile_name
>>
>> # Display result as CSV and write it to the output file
>> # First the column headers...
>> print(re_table.header)
>> for s in re_table.header:
>> outfile.write("%s;" % s)
>> outfile.write("\n")
>>
>> # ...now all row's which were parsed by TextFSM
>> counter = 0
>> for row in fsm_results:
>> print(row)
>> for s in row:
>> outfile.write("%s;" % s)
>> outfile.write("\n")
>> counter += 1
>> print("Write %d records" % counter)
>>
>> Regards,
>> *Surjeet Singh*
>> Technical Specialist – Networks DATA
>> CCNA, CCNP(R)
>> Cell : +917838707047
>>
>> To become bigger person,need to walk with bigger Vision 
>>
>> On Thu, Jan 25, 2018 at 12:27 AM, Claudia de Luna <de

Re: [ansible-project] Re: Simple cisco IOS show version

2018-01-27 Thread Surjeet Singh
Hi Claudia,

i am strugling with with issue in putting textfsm in loop. i can read all
my file end with .txt but i have issue in moving for loop so i can run
textfsml on all files instead of last file.

can you please help me with that.

import jtextfsm as textfsm
import glob, os

os.chdir("/etc/ansible/facts/")
for file in glob.glob("*_iosfacts.txt"):
input_file = open(file)
raw_text_data = input_file.read()
input_file.close()

# Run the text through the FSM.
# The argument 'template' is a file handle and 'raw_text_data' is a
# string with the content from the show_inventory.txt file
template =
open("/etc/ansible/parse-inventory-with-textfsm/show_inventory_multiple.textfsm")
re_table = textfsm.TextFSM(template)
fsm_results = re_table.ParseText( raw_text_data)

# the results are written to a CSV file
outfile_name =
open("/etc/ansible/parse-inventory-with-textfsm//outfile.csv", "w+")
outfile = outfile_name

# Display result as CSV and write it to the output file
# First the column headers...
print(re_table.header)
for s in re_table.header:
outfile.write("%s;" % s)
outfile.write("\n")

# ...now all row's which were parsed by TextFSM
counter = 0
for row in fsm_results:
print(row)
for s in row:
outfile.write("%s;" % s)
outfile.write("\n")
counter += 1
print("Write %d records" % counter)

Regards,
*Surjeet Singh*
Technical Specialist – Networks DATA
CCNA, CCNP(R)
Cell : +917838707047

To become bigger person,need to walk with bigger Vision 

On Thu, Jan 25, 2018 at 12:27 AM, Claudia de Luna <delu...@gmail.com> wrote:

> Hi Surjeet,
>
> There are a couple of ways to approach this.
>
> What I typically do is save a file of show commands for each device and
> then process those files using TextFSM.
>
> - local_action: copy content="{{ output }}" dest="./FACTs/{{
> inventory_hostname }}-facts.txt"
>
> To basically concatenate to one file I suspect it would have to involve
> set_fact and some processing..maybe a template.
>
> If I get some time I'll see if I can come up with something that makes
> sense.
>
> Claudia
>
>
>
> On Tue, Jan 23, 2018 at 10:51 PM, Surjeet Singh <
> surjeet.singh0...@gmail.com> wrote:
>
>> Thank you for your response. Please excuse me for my multiple question i
>> am new to this programming world.
>>
>> now i manage to collect the facts using the ansible get_fact module. i
>> will further spend time today for regular expression.
>>
>> my playbook looks like below:
>>
>> ---
>> - name: collect device facts and display OS version
>>   hosts: "{{ inventory | default('all') }}"
>>   gather_facts: false
>>   connection: local
>>   ignore_errors: yes
>>
>>   vars:
>> cli:
>>   host: "{{ inventory_hostname }}"
>>   username: cisco
>>   password: cisco
>>
>>   tasks:
>> - ios_facts:
>>   gather_subset: all
>>   provider: "{{ cli }}"
>>   register: facts_output
>>
>> - debug: var=facts_output.ansible_facts.ansible_net_hostname
>> - debug: var=facts_output.ansible_facts.ansible_net_version
>> - debug: var=facts_output.ansible_facts.ansible_net_model
>>
>> - name: write the inventory in into file
>>   copy: content="{{ facts_output.ansible_facts.ansible_net_hostname,
>> facts_output.ansible_facts.ansible_net_version ,
>> facts_output.ansible_facts.ansible_net_model }}"
>> dest="facts/iosfacts.txt"
>>
>> now my question is there any way to copy this information excel for all
>> devices because currently i am getting information for only one
>> device.since information is getting overwrite everytime instead of append.
>>
>> can we use loop to achieve above task ?
>>
>>
>>
>> Regards,
>> *Surjeet Singh*
>> Technical Specialist – Networks DATA
>> CCNA, CCNP(R)
>> Cell : +917838707047 <+91%2078387%2007047>
>>
>> To become bigger person,need to walk with bigger Vision 
>>
>> On Tue, Jan 23, 2018 at 9:20 PM, Claudia de Luna <delu...@gmail.com>
>> wrote:
>>
>>> Hi Surjeet,
>>>
>>> My intent with the second message was to show you the power of the
>>> ios/nxos facts modules.  These modules return device information in a
>>> structured way so that you don't have to mine your output with regular
>>> expressions if it returns the data you are looking for.  With the ios facts
>>> module you get version, serial number, ip addresses (ipv4/6), hostname,
>>>

Re: [ansible-project] Re: Simple cisco IOS show version

2018-01-24 Thread Surjeet Singh
Thank you ...

On 25-Jan-2018 12:28 AM, "Claudia de Luna" <delu...@gmail.com> wrote:

> Hi Surjeet,
>
> There are a couple of ways to approach this.
>
> What I typically do is save a file of show commands for each device and
> then process those files using TextFSM.
>
> - local_action: copy content="{{ output }}" dest="./FACTs/{{
> inventory_hostname }}-facts.txt"
>
> To basically concatenate to one file I suspect it would have to involve
> set_fact and some processing..maybe a template.
>
> If I get some time I'll see if I can come up with something that makes
> sense.
>
> Claudia
>
>
>
> On Tue, Jan 23, 2018 at 10:51 PM, Surjeet Singh <
> surjeet.singh0...@gmail.com> wrote:
>
>> Thank you for your response. Please excuse me for my multiple question i
>> am new to this programming world.
>>
>> now i manage to collect the facts using the ansible get_fact module. i
>> will further spend time today for regular expression.
>>
>> my playbook looks like below:
>>
>> ---
>> - name: collect device facts and display OS version
>>   hosts: "{{ inventory | default('all') }}"
>>   gather_facts: false
>>   connection: local
>>   ignore_errors: yes
>>
>>   vars:
>> cli:
>>   host: "{{ inventory_hostname }}"
>>   username: cisco
>>   password: cisco
>>
>>   tasks:
>> - ios_facts:
>>   gather_subset: all
>>   provider: "{{ cli }}"
>>   register: facts_output
>>
>> - debug: var=facts_output.ansible_facts.ansible_net_hostname
>> - debug: var=facts_output.ansible_facts.ansible_net_version
>> - debug: var=facts_output.ansible_facts.ansible_net_model
>>
>> - name: write the inventory in into file
>>   copy: content="{{ facts_output.ansible_facts.ansible_net_hostname,
>> facts_output.ansible_facts.ansible_net_version ,
>> facts_output.ansible_facts.ansible_net_model }}"
>> dest="facts/iosfacts.txt"
>>
>> now my question is there any way to copy this information excel for all
>> devices because currently i am getting information for only one
>> device.since information is getting overwrite everytime instead of append.
>>
>> can we use loop to achieve above task ?
>>
>>
>>
>> Regards,
>> *Surjeet Singh*
>> Technical Specialist – Networks DATA
>> CCNA, CCNP(R)
>> Cell : +917838707047 <+91%2078387%2007047>
>>
>> To become bigger person,need to walk with bigger Vision 
>>
>> On Tue, Jan 23, 2018 at 9:20 PM, Claudia de Luna <delu...@gmail.com>
>> wrote:
>>
>>> Hi Surjeet,
>>>
>>> My intent with the second message was to show you the power of the
>>> ios/nxos facts modules.  These modules return device information in a
>>> structured way so that you don't have to mine your output with regular
>>> expressions if it returns the data you are looking for.  With the ios facts
>>> module you get version, serial number, ip addresses (ipv4/6), hostname,
>>> etc..
>>>
>>> If you take the output and paste it into http://jsoneditoronline.org/
>>> you can "decompose" the ansible_facts object.   Here is the first part so
>>> you can see that ansible_facts is a dictionary and the first key is
>>> ansible_net_all_ipv4_addresses and the value is a list with two IPs (the
>>> two IPv4 ips this switch has configured).  The next key would hold all the
>>> IPv6 IPs in list but as you can see the list is empty [] because I don't
>>> have ipv6 configured on this switch.
>>>
>>>>
>>>> "ansible_facts": {
>>>> "ansible_net_all_ipv4_addresses": [
>>>> "10.1.10.25",
>>>> "192.0.2.33"
>>>> ],
>>>> "ansible_net_all_ipv6_addresses": [],
>>>> "ansible_net_filesystems": [
>>>> "flash:"
>>>> ],
>>>>
>>>
>>> In this  playbook I use the ios_facts module to get the version of code
>>> in the ansible_net_version key value pair that is part of the ansible_facts
>>> "dictionary".
>>>
>>>   tasks:
>>>> - name: Gather IOS Facts
>>>>   ios_facts:
>>>
>>>
>>>
>>> so the last line
>>>
>>> debug

Re: [ansible-project] Re: Simple cisco IOS show version

2018-01-23 Thread Surjeet Singh
Thank you for your response. Please excuse me for my multiple question i am
new to this programming world.

now i manage to collect the facts using the ansible get_fact module. i will
further spend time today for regular expression.

my playbook looks like below:

---
- name: collect device facts and display OS version
  hosts: "{{ inventory | default('all') }}"
  gather_facts: false
  connection: local
  ignore_errors: yes

  vars:
cli:
  host: "{{ inventory_hostname }}"
  username: cisco
  password: cisco

  tasks:
- ios_facts:
  gather_subset: all
  provider: "{{ cli }}"
  register: facts_output

- debug: var=facts_output.ansible_facts.ansible_net_hostname
- debug: var=facts_output.ansible_facts.ansible_net_version
- debug: var=facts_output.ansible_facts.ansible_net_model

- name: write the inventory in into file
  copy: content="{{ facts_output.ansible_facts.ansible_net_hostname,
facts_output.ansible_facts.ansible_net_version ,
facts_output.ansible_facts.ansible_net_model }}" dest="facts/iosfacts.txt"

now my question is there any way to copy this information excel for all
devices because currently i am getting information for only one
device.since information is getting overwrite everytime instead of append.

can we use loop to achieve above task ?



Regards,
*Surjeet Singh*
Technical Specialist – Networks DATA
CCNA, CCNP(R)
Cell : +917838707047

To become bigger person,need to walk with bigger Vision 

On Tue, Jan 23, 2018 at 9:20 PM, Claudia de Luna <delu...@gmail.com> wrote:

> Hi Surjeet,
>
> My intent with the second message was to show you the power of the
> ios/nxos facts modules.  These modules return device information in a
> structured way so that you don't have to mine your output with regular
> expressions if it returns the data you are looking for.  With the ios facts
> module you get version, serial number, ip addresses (ipv4/6), hostname,
> etc..
>
> If you take the output and paste it into http://jsoneditoronline.org/ you
> can "decompose" the ansible_facts object.   Here is the first part so you
> can see that ansible_facts is a dictionary and the first key is
> ansible_net_all_ipv4_addresses and the value is a list with two IPs (the
> two IPv4 ips this switch has configured).  The next key would hold all the
> IPv6 IPs in list but as you can see the list is empty [] because I don't
> have ipv6 configured on this switch.
>
>>
>> "ansible_facts": {
>> "ansible_net_all_ipv4_addresses": [
>> "10.1.10.25",
>> "192.0.2.33"
>> ],
>> "ansible_net_all_ipv6_addresses": [],
>> "ansible_net_filesystems": [
>> "flash:"
>> ],
>>
>
> In this  playbook I use the ios_facts module to get the version of code in
> the ansible_net_version key value pair that is part of the ansible_facts
> "dictionary".
>
>   tasks:
>> - name: Gather IOS Facts
>>   ios_facts:
>
>
>
> so the last line
>
> debug: var=facts_output.ansible_facts.ansible_net_version
>
>
> is just printing the value of the ansible_net_version key from the
> ansible_facts dictionary returned by the ios_facts module that I stuffed in
> a varialbe called "facts_output"
>
> Having said all of that, there are many scenarios where you will need to
> parse your output for data that has not been nicely packaged up for us in
> these ansible modules so it is a valuable skill with many approaches.  You
> want to use the one you are most comfortable with but you also don't want
> to work any harder than you have to!
>
> Here are some of the approaches I'm aware of and maybe others can chime in
> with what works for them.
>
> *1.  embed regexp in the command you send with the ios_command module.*
> Here is sample output from the attached playbook.  I'm just sending the
> regexp as part of the command as you would if you were in the CLI.
> Ethan Banks at Packet Pushers does a nice little summary
> <http://packetpushers.net/rocking-your-show-commands-with-regex/>and I'm
> sure you can Google a bunch more
>
> root@e8d7daa45b5b:/ansible/ansible2_4_base# ansible-playbook -i hosts
>> get_ios_cmd_filter.yml
>> PLAY [cisco] 
>> 
>> 
>> TASK [Show command with embedded regexp inc connected for all Conneced
>> interfaces] 
>> **

Re: [ansible-project] Re: Simple cisco IOS show version

2018-01-22 Thread Surjeet Singh
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)
Cell : +917838707047

To become bigger person,need to walk with bigger Vision 

On Sun, Jan 21, 2018 at 11:59 PM, Claudia de Luna <delu...@gmail.com> 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 <valeri...@gmail.com> 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
>>>> “ho

[ansible-project] VARIABLE IS NOT DEFINED!

2018-01-19 Thread Surjeet Singh
am i impacted with some bug ?

 "VARIABLE IS NOT DEFINED!"

root@eve-ng:/etc/ansible# ansible-playbook test.yaml 

PLAY [collect device facts and display OS version] 
**

TASK [run the show commands] 

 [WARNING]: argument username has been deprecated and will be removed in a 
future version
 [WARNING]: argument host has been deprecated and will be removed in a 
future version
 [WARNING]: argument password has been deprecated and will be removed in a 
future version
ok: [8.8.8.8]
ok: [5.5.5.5]

TASK [debug] 

ok: [8.8.8.8] => {
"version.stdout[0].Version": "VARIABLE IS NOT DEFINED!"
}
ok: [5.5.5.5] => {
"version.stdout[0].Version": "VARIABLE IS NOT DEFINED!"
}

PLAY RECAP 
**
5.5.5.5: ok=2changed=0unreachable=0
failed=0   
8.8.8.8: ok=2changed=0unreachable=0
failed=0   



root@eve-ng:/etc/ansible# more test.yaml 
---
- name: collect device facts and display OS version
  hosts: "{{ inventory | default('all') }}"
  gather_facts: no
  connection: local

  
  tasks:
- name: run the show commands
  ios_command:
commands:
  - show version
host: "{{ inventory_hostname }}"
username: cisco
password: cisco
  register: version
  
- debug: var=version.stdout[0].Version

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0d8db0ae-b67d-4b73-be92-3c5d5e1133ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] getting facts from remote devices

2018-01-19 Thread Surjeet Singh
Hi,

I am new to this community and new ansible as so please excuse me of my 
stupid mistakes.

referring to peter's webinar i am trying to collect device information 
using reguler expressions.it seems it through me error as bellow:-

TASK [network_facts : set hostname fact] 

task path: /etc/ansible/roles/network_facts/tasks/ios.yaml:14
fatal: [8.8.8.8]: FAILED! => {
"msg": "Unexpected templating type error occurred on ({{ 
output.stdout[2] | regex_search('^hostname (.+)$', '1') | first }}): 
'NoneType' object is not iterable"
}
fatal: [5.5.5.5]: FAILED! => {
"msg": "Unexpected templating type error occurred on ({{ 
output.stdout[2] | regex_search('^hostname (.+)$', '1') | first }}): 
'NoneType' object is not iterable"
}
to retry, use: --limit @/etc/ansible/facts.retry

PLAY RECAP 
**
5.5.5.5: ok=2changed=0unreachable=0
failed=1   
8.8.8.8: ok=2changed=0unreachable=0
failed=1

i can confirm that ansible is able to login on the device and is able 
excute the required commend to collect the information but it seems reguler 
expression is not correct.

Here is my play book:

---
- name: collect device facts and display OS version
  hosts: "{{ inventory | default('all') }}"
  gather_facts: no
  connection: local

  roles:
- { role: network_facts }

  tasks:
- debug: msg="Node {{ hostname }} is type {{ device_os }} running 
software version {{ version }}"


below is task yml file:-
---
- name: collect output from ios device
  ios_command:
commands:
  - show version
  - show interfaces
  - show running-config
provider: "{{ ios_provider }}"
  register: output

# common facts
#

- name: set hostname fact
  set_fact: hostname="{{ output.stdout[2] | regex_search('^hostname (.+)$', 
'\\1') | first }}"

- name: set interfaces fact
  set_fact: interfaces="{{ output.stdout[1] | 
regex_findall('^[L|G|A|B|C|D||M|N|P|T|V]\\S+') }}"

- name: set version fact
  set_fact: version="{{ output.stdout[0] | regex_search('Version (\\S+),', 
'\\1') | first }}"

- name: set config fact
  set_fact: config="{{ output.stdout[2] }}"

- name: set config_lines fact
  set_fact: config_lines="{{ config.split('\n') }}"

Regards/Surjeet
 

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d674db41-aaaf-400d-99a6-1282c156de10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] fatal: [localhost] = One or more undefined variables: 'dict object' has no attribute u'fireball-iad-dev-fireball'

2015-04-20 Thread surjeet singh
Hi ,

I am getting the below error, while creating the beanstalk environment on 
AWS, I've tried ansible version 1.8.4 and 1.9.0.1 and the issue comes in 
both..

can any one guide me on how to rectify this issue.. I am pretty new to 
ansible and aws.

fatal: [localhost] = One or more undefined variables: 'dict object' has no 
attribute u'fireball-iad-dev-fireball'

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8f93faec-88a5-496f-b206-696d7758e493%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.