Why is this telling me the variable is undefined?

31 views
Skip to first unread message

Chrono 7

unread,
Aug 25, 2019, 9:44:40 PM8/25/19
to Ansible Project
I tried to follow along with a similar approach to the docs on read_csv here. I'm not sure why I'm getting this error returned when the value of systems is defined just above the set_fact:


fatal: [127.0.0.1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'systems' is undefined\n\nThe error appears to have been in 'system_info.yaml': line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n    - name: Read the CSV & Set Values\n      ^ here\n"}

Here's what my playbook looks like:


---

- name: Import CSV Containing Info For System(s) To Prep
  hosts
: 127.0.0.1

  tasks
:
 
- name: Read the CSV & Set Values
    read_csv
:
      path
: systems.csv
   
register: systems
    delegate_to
: localhost
 
    set_fact
:
      IP
: "{{ systems.list.1.IPAddress }}"

Any ideas on this?

Kai Stian Olstad

unread,
Aug 26, 2019, 3:42:15 AM8/26/19
to ansible...@googlegroups.com
On 26.08.2019 03:44, Chrono 7 wrote:
> fatal: [127.0.0.1]: FAILED! => {"msg": "The task includes an option
> with an
> undefined variable. The error was: 'systems' is undefined\n\nThe error
> appears to have been in 'system_info.yaml': line 7, column 7, but
> may\nbe
> elsewhere in the file depending on the exact syntax problem.\n\nThe
> offending line appears to be:\n\n tasks:\n - name: Read the CSV &
> Set
> Values\n ^ here\n"}
>
> Here's what my playbook looks like:
>
>
> ---
>
> - name: Import CSV Containing Info For System(s) To Prep
> hosts: 127.0.0.1
>
> tasks:
> - name: Read the CSV & Set Values
> read_csv:
> path: systems.csv
> register: systems
> delegate_to: localhost
>
> set_fact:
> IP: "{{ systems.list.1.IPAddress }}"
>
> Any ideas on this?

You are missing the dash in front of set_fact.

--
Kai Stian Olstad

Chrono 7

unread,
Aug 26, 2019, 8:34:40 AM8/26/19
to Ansible Project
I get an error stating:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.


The error appears to have been in 'system_info.yaml': line 7, column 7,
but may
be elsewhere
in the file depending on the exact syntax problem.

The offending line appears to be:


  tasks
:

   
- name: Read the CSV & Set Values

     
^ here

That's with my file being reworked to:

---

- name: Import CSV Containing Info For System(s) To Prep
  hosts
: 127.0.0.1

  tasks
:
   
- name: Read the CSV & Set Values
     read_csv
:
     path
: systems.csv
     
register: systems
     delegate_to
:
localhost

   
- set_fact:
       IP
: "{{ systems.list.1.IPAddress }}"

I'm just trying to store values from a CSV file to a variable, I haven't had any luck so far unfortunately.


---

- name: Import CSV Containing Info For System(s) To Prep
hosts: 127.0.0.1

tasks:
- name: Read the CSV & Set Values
read_csv:
path: systems.csv
register: systems
delegate_to: localhost

- set_fact:
IP: "{{ systems.list.1.IPAddress }}"

Stefan Hornburg (Racke)

unread,
Aug 26, 2019, 8:46:50 AM8/26/19
to ansible...@googlegroups.com
On 8/26/19 2:34 PM, Chrono 7 wrote:
> I get an error stating:
>
> |
> ERROR!noaction detected intask.Thisoften indicates a misspelled modulename,orincorrect modulepath.
>
> Theerror appears to have been in'system_info.yaml':line 7,column 7,but may
> be elsewhere inthe file depending on the exact syntax problem.
>
> Theoffending line appears to be:
>
>   tasks:
>     -name:Readthe CSV &SetValues
>       ^here
> |
>
> That's with my file being reworked to:
>
> |
> ---
>
> -name:ImportCSV ContainingInfoForSystem(s)ToPrep
>   hosts:127.0.0.1
>
>   tasks:
>    -name:Readthe CSV &SetValues
>      read_csv:
>      path:systems.csv
>      register:systems
>      delegate_to:localhost
>
>    -set_fact:
>        IP:"{{ systems.list.1.IPAddress }}"
> |
>
> I'm just trying to store values from a CSV file to a variable, I haven't had any luck so far unfortunately.
>
>

From the docs:

# Read a CSV file and access the first item
- name: Read users from CSV file and return a list
read_csv:
path: users.csv
register: users
delegate_to: localhost

You need to intend the parameters for the Ansible module (path in your case).

Regards
Racke



--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Dick Visser

unread,
Aug 26, 2019, 9:11:21 AM8/26/19
to ansible...@googlegroups.com
On Mon, 26 Aug 2019 at 14:34, Chrono 7 <chro...@gmail.com> wrote:
I get an error stating:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in 'system_info.yaml': line 7, column 7, but may
be elsewhere
in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks
:
   
- name: Read the CSV & Set Values
     
^ here

That's with my file being reworked to:

---

- name: Import CSV Containing Info For System(s) To Prep
  hosts
: 127.0.0.1

  tasks
:
   
- name: Read the CSV & Set Values
     read_csv
:
     path
: systems.csv
     
register: systems
     delegate_to
: localhost

   
- set_fact:
       IP
: "{{ systems.list.1.IPAddress }}"



Your indentation is wrong.

try:


---

- name: Import CSV Containing Info For System(s) To Prep
  hosts
: 127.0.0.1

  tasks
:
   
- name: Read the CSV & Set Values
     read_csv
:
       path
: systems.csv
     
register: systems
     delegate_to
: localhost

   
- set_fact:
       IP: "{{ systems.list.1.IPAddress }}" 


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Karl Auer

unread,
Aug 26, 2019, 10:56:20 AM8/26/19
to ansible-project
path: is not indented?

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bc158058-cd37-45f2-86df-a0aff57d356b%40googlegroups.com.


--
Karl Auer

Email  : ka...@2pisoftware.com
Website: http://2pisoftware.com


GPG/PGP : 301B 1F4E 624D AD99 242C 7A68 EC24 7113 E854 4A4E
Previous:
958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816

Zolvaring

unread,
Aug 26, 2019, 11:02:54 AM8/26/19
to Ansible Project
Your original spacing looks fine other than missing the dash for set fact. The original error is indicating that the "system" doesn't exist when your CSV read task looks for "system.csv". I would check that "system.csv" is defined and add this before the csv read task to troubleshoot:

- debug:
var: system
- debug:
var: system.csv

Chrono 7

unread,
Aug 26, 2019, 6:15:04 PM8/26/19
to Ansible Project
 
 Appreciate the responses so far everyone. I've indented the path line as suggested but still get the following error:


ERROR
! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in 'system_info.yaml': line 7, column 7,
but may
be elsewhere
in the file depending on the exact syntax problem.

The offending line appears to be:


  tasks
:

 
- name: Read the CSV & Set Values

   
^ here


Here's the latest of what my file currently looks like:


---

- name: Import CSV Containing Info For System(s) To Prep
  hosts
: 127.0.0.1

  tasks
:
 
- name: Read the CSV & Set Values
    read_csv
:
      path
: systems.csv
   
register: systems
    delegate_to
:
localhost

   
- set_fact:
       IP
: "{{ systems.list.1.IPAddress }}"


A couple things I've tried:

1. I've tried playing around with the indentations of the - name and - set_fact where I've increased it by one indent.
2. I've tried referencing the absolute path of the systems.csv file within path: in case it wasn't able to find this for whatever reason. The csv file itself is in the same directory as the playbook as well, and since I'm not referencing a variable at this point, I'm not sure that I'd have to define a systems variable itself containing the path to the CSV file

I'm currently running 2.5.1 as well and admittedly am new to Ansible.


Zolvaring

unread,
Aug 26, 2019, 6:36:26 PM8/26/19
to ansible...@googlegroups.com
Hello, 

I was having a moment earlier when I read your path as an actual variable that was my mistake. To be more helpful though, I replicated your code on my setup and ran into the same error. On checking the docs I saw that read_csv was added in 2.8, and after updating to 2.8 the "no action detected in task" error is gone.

Hopefully this helps

--
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-proje...@googlegroups.com.

Chrono 7

unread,
Aug 26, 2019, 6:46:33 PM8/26/19
to Ansible Project
 Woohoo, that was it. Updated and it's working now. Thanks a lot, checking my version was the last thing on my mind for whatever reason
Reply all
Reply to author
Forward
0 new messages