set_fact moudle error ansible

194 views
Skip to first unread message

Sandy Hung

unread,
Mar 30, 2020, 11:55:10 PM3/30/20
to Ansible Project
Hi 

error msg
fatal: [localhost]: FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ansible_facts'\n\nThe error appears to be in '/home/ldap/createefs.yml': line 37, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n     - set_fact:\n       ^ here\n"
}

 - hosts: localhost
   connection: local
   gather_facts: no

   vars_files:
     - ec2key.yml
   vars:
     efs_vol_name: "test_efs"


   tasks:

     - name: Create EFS fileserver
       efs:
        state: present
        region: "ap-southeast-1"
        name: "test_efs"
        tags:
          Name: "test_efstag"
        targets:
          - subnet_id: "subnet-46817120"
            security_groups: [ "sg-073c16c36bea62794" ]
        performance_mode: general_purpose
        encrypt: yes

#     - name: efs mount to ec2
#       vars:
#         efs_vol_name: "test_efs"

     - local_action:
         module: efs_info
         name: "{{ efs_vol_name }}"
       run_once: true
       register: _efs_fact

     - set_fact:
         _efs_fact_id: "{{ efs_fact.ansible_facts.efs[0].file_system_id }}"

     - name: install efs libs
       apt:
         name: "{{ item }}"
         state: present
       become: yes
       with_items:
         - nfs-common
     - name: Create data store directory for efs mount
       file:
         dest: "/home/ec2-user/{{ efs_vol_name }}"
         state: directory

     - name: mount efs volume
       mount:
         path: "/home/ec2-user/{{ efs_vol_name }}"
         src: "{{ _efs_fact_id }}.efs.ap-southeast-1.amazonaws.com:/"
         fstype: "nfs4"
         opts: "nfssevers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport"
         state: mounted
       become: yes


Vladimir Botka

unread,
Mar 31, 2020, 2:34:13 AM3/31/20
to Sandy Hung, ansible...@googlegroups.com
On Mon, 30 Mar 2020 20:55:10 -0700 (PDT)
Sandy Hung <sandy...@abagile.com> wrote:

> fatal: [localhost]: FAILED! => {
> "msg": "The task includes an option with an undefined variable. The
> error was: 'dict object' has no attribute 'ansible_facts'
> [...]
> - local_action:
> module: efs_info
> name: "{{ efs_vol_name }}"
> run_once: true
> register: _efs_fact
>
> - set_fact:
> _efs_fact_id: "{{ efs_fact.ansible_facts.efs[0].file_system_id }}"

There are 2 problems.

1) "efs_info" says: "Note that the efs_info module no longer returns
ansible_facts!"
https://docs.ansible.com/ansible/latest/modules/efs_info_module.html#synopsis

2) The underscore "_" is missing in front of the variable "_efs_fact". Correct

- set_fact:
_efs_fact_id: "{{ _efs_fact. ... }}"

But, first you might want to take a look at the content of the registered
variable and see what is available

- debug:
var: _efs_fact

HTH,

-vlado

Sandy Hung

unread,
Mar 31, 2020, 4:16:18 AM3/31/20
to Ansible Project
thank  your help
I have problem mount efs  volume show msg   "msg": "Error mounting /home/ec2-user/test_efs: mount.nfs4: Connection timed out\n"
I have add to hosts 
Reply all
Reply to author
Forward
0 new messages