Creating symlinks with ansible using variables












1















I'm doing a playbook to create symlinks of nodejs, npm and gulp because I need to use a specific version and to install it all I'm just unzipping folders to /opt/ where all this is going to stay.



The task with items I'm using for creating the links are:



- name: Create NPM symlink
file:
src: '{{ item.src_dir }}/{{ item.src_name }}'
dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
owner: "{{ ansible_ssh_user }}"
group: "{{ ansible_ssh_user }}"
state: link
with_items:
- { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}" }
- { dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


all the variables used in the items "zone" are declared in the host file as such:
npm_real_dir=/opt/nodejs/node-v6.11.2-linux-x64/lib/node_modules/npm/bin



npm_real_name=npm-cli.js



nodenpm_link_dir=/opt/nodejs/node-v6.11.2-linux-x64/bin



npm_link_name=npm



ansible_ssh_user=vagrant



And I'm getting the error:



FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'dest_dir'


Which I'm not understanding since all the variables used in the task are declared and correct. I made a similar task without items:



- name: Create symbolic link for npm
file:
src: '{{ npm_real_dir }}/{{ npm_real_name }}'
path: '{{ nodenpm_link_dir }}/{{ npm_link_name }}'
owner: "{{ ansible_ssh_user }}"
group: "{{ ansible_ssh_user }}"
state: link


And its working, however the structure is the same as before, just without the items.



At this point I just want to know if its a known bug, if there is any issue in using items to create links, or if I did a stupid mistake and gain knowledge about it



Thanks in advance










share|improve this question



























    1















    I'm doing a playbook to create symlinks of nodejs, npm and gulp because I need to use a specific version and to install it all I'm just unzipping folders to /opt/ where all this is going to stay.



    The task with items I'm using for creating the links are:



    - name: Create NPM symlink
    file:
    src: '{{ item.src_dir }}/{{ item.src_name }}'
    dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
    owner: "{{ ansible_ssh_user }}"
    group: "{{ ansible_ssh_user }}"
    state: link
    with_items:
    - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}" }
    - { dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


    all the variables used in the items "zone" are declared in the host file as such:
    npm_real_dir=/opt/nodejs/node-v6.11.2-linux-x64/lib/node_modules/npm/bin



    npm_real_name=npm-cli.js



    nodenpm_link_dir=/opt/nodejs/node-v6.11.2-linux-x64/bin



    npm_link_name=npm



    ansible_ssh_user=vagrant



    And I'm getting the error:



    FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'dest_dir'


    Which I'm not understanding since all the variables used in the task are declared and correct. I made a similar task without items:



    - name: Create symbolic link for npm
    file:
    src: '{{ npm_real_dir }}/{{ npm_real_name }}'
    path: '{{ nodenpm_link_dir }}/{{ npm_link_name }}'
    owner: "{{ ansible_ssh_user }}"
    group: "{{ ansible_ssh_user }}"
    state: link


    And its working, however the structure is the same as before, just without the items.



    At this point I just want to know if its a known bug, if there is any issue in using items to create links, or if I did a stupid mistake and gain knowledge about it



    Thanks in advance










    share|improve this question

























      1












      1








      1








      I'm doing a playbook to create symlinks of nodejs, npm and gulp because I need to use a specific version and to install it all I'm just unzipping folders to /opt/ where all this is going to stay.



      The task with items I'm using for creating the links are:



      - name: Create NPM symlink
      file:
      src: '{{ item.src_dir }}/{{ item.src_name }}'
      dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
      owner: "{{ ansible_ssh_user }}"
      group: "{{ ansible_ssh_user }}"
      state: link
      with_items:
      - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}" }
      - { dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


      all the variables used in the items "zone" are declared in the host file as such:
      npm_real_dir=/opt/nodejs/node-v6.11.2-linux-x64/lib/node_modules/npm/bin



      npm_real_name=npm-cli.js



      nodenpm_link_dir=/opt/nodejs/node-v6.11.2-linux-x64/bin



      npm_link_name=npm



      ansible_ssh_user=vagrant



      And I'm getting the error:



      FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'dest_dir'


      Which I'm not understanding since all the variables used in the task are declared and correct. I made a similar task without items:



      - name: Create symbolic link for npm
      file:
      src: '{{ npm_real_dir }}/{{ npm_real_name }}'
      path: '{{ nodenpm_link_dir }}/{{ npm_link_name }}'
      owner: "{{ ansible_ssh_user }}"
      group: "{{ ansible_ssh_user }}"
      state: link


      And its working, however the structure is the same as before, just without the items.



      At this point I just want to know if its a known bug, if there is any issue in using items to create links, or if I did a stupid mistake and gain knowledge about it



      Thanks in advance










      share|improve this question














      I'm doing a playbook to create symlinks of nodejs, npm and gulp because I need to use a specific version and to install it all I'm just unzipping folders to /opt/ where all this is going to stay.



      The task with items I'm using for creating the links are:



      - name: Create NPM symlink
      file:
      src: '{{ item.src_dir }}/{{ item.src_name }}'
      dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
      owner: "{{ ansible_ssh_user }}"
      group: "{{ ansible_ssh_user }}"
      state: link
      with_items:
      - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}" }
      - { dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


      all the variables used in the items "zone" are declared in the host file as such:
      npm_real_dir=/opt/nodejs/node-v6.11.2-linux-x64/lib/node_modules/npm/bin



      npm_real_name=npm-cli.js



      nodenpm_link_dir=/opt/nodejs/node-v6.11.2-linux-x64/bin



      npm_link_name=npm



      ansible_ssh_user=vagrant



      And I'm getting the error:



      FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'dest_dir'


      Which I'm not understanding since all the variables used in the task are declared and correct. I made a similar task without items:



      - name: Create symbolic link for npm
      file:
      src: '{{ npm_real_dir }}/{{ npm_real_name }}'
      path: '{{ nodenpm_link_dir }}/{{ npm_link_name }}'
      owner: "{{ ansible_ssh_user }}"
      group: "{{ ansible_ssh_user }}"
      state: link


      And its working, however the structure is the same as before, just without the items.



      At this point I just want to know if its a known bug, if there is any issue in using items to create links, or if I did a stupid mistake and gain knowledge about it



      Thanks in advance







      ansible symlink






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 15:15









      Fábio CarameloFábio Caramelo

      348




      348
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The issue is that you're passing two different objects to the with_items property. The first object has two properties (src_dir and src_name), while the second object has two different properties (dest_dir and dest_name).



          It looks like you want to combine them into a single object like this:



          - name: Create NPM symlink
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


          That should work better and get rid of the error, but in this case you don't really need the with_items, since it's only one item that you're dealing with. You can add more objects for other tools, e.g. gulp in the same manner, e.g. like this:



          - name: Create symlinks
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }
          - { src_dir: "{{ gulp_real_dir }}", src_name: "{{ gulp_real_name }}", dest_dir: "{{ gulp_link_dir }}", dest_name: "{{ gulp_link_name }}" }





          share|improve this answer



















          • 1





            oh ok. makes sence about an undefined variable when you are not even passing it. Thanks for your answer :)

            – Fábio Caramelo
            Nov 14 '18 at 16:25











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303363%2fcreating-symlinks-with-ansible-using-variables%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The issue is that you're passing two different objects to the with_items property. The first object has two properties (src_dir and src_name), while the second object has two different properties (dest_dir and dest_name).



          It looks like you want to combine them into a single object like this:



          - name: Create NPM symlink
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


          That should work better and get rid of the error, but in this case you don't really need the with_items, since it's only one item that you're dealing with. You can add more objects for other tools, e.g. gulp in the same manner, e.g. like this:



          - name: Create symlinks
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }
          - { src_dir: "{{ gulp_real_dir }}", src_name: "{{ gulp_real_name }}", dest_dir: "{{ gulp_link_dir }}", dest_name: "{{ gulp_link_name }}" }





          share|improve this answer



















          • 1





            oh ok. makes sence about an undefined variable when you are not even passing it. Thanks for your answer :)

            – Fábio Caramelo
            Nov 14 '18 at 16:25
















          1














          The issue is that you're passing two different objects to the with_items property. The first object has two properties (src_dir and src_name), while the second object has two different properties (dest_dir and dest_name).



          It looks like you want to combine them into a single object like this:



          - name: Create NPM symlink
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


          That should work better and get rid of the error, but in this case you don't really need the with_items, since it's only one item that you're dealing with. You can add more objects for other tools, e.g. gulp in the same manner, e.g. like this:



          - name: Create symlinks
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }
          - { src_dir: "{{ gulp_real_dir }}", src_name: "{{ gulp_real_name }}", dest_dir: "{{ gulp_link_dir }}", dest_name: "{{ gulp_link_name }}" }





          share|improve this answer



















          • 1





            oh ok. makes sence about an undefined variable when you are not even passing it. Thanks for your answer :)

            – Fábio Caramelo
            Nov 14 '18 at 16:25














          1












          1








          1







          The issue is that you're passing two different objects to the with_items property. The first object has two properties (src_dir and src_name), while the second object has two different properties (dest_dir and dest_name).



          It looks like you want to combine them into a single object like this:



          - name: Create NPM symlink
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


          That should work better and get rid of the error, but in this case you don't really need the with_items, since it's only one item that you're dealing with. You can add more objects for other tools, e.g. gulp in the same manner, e.g. like this:



          - name: Create symlinks
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }
          - { src_dir: "{{ gulp_real_dir }}", src_name: "{{ gulp_real_name }}", dest_dir: "{{ gulp_link_dir }}", dest_name: "{{ gulp_link_name }}" }





          share|improve this answer













          The issue is that you're passing two different objects to the with_items property. The first object has two properties (src_dir and src_name), while the second object has two different properties (dest_dir and dest_name).



          It looks like you want to combine them into a single object like this:



          - name: Create NPM symlink
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }


          That should work better and get rid of the error, but in this case you don't really need the with_items, since it's only one item that you're dealing with. You can add more objects for other tools, e.g. gulp in the same manner, e.g. like this:



          - name: Create symlinks
          file:
          src: '{{ item.src_dir }}/{{ item.src_name }}'
          dest: '{{ item.dest_dir }}/{{ item.dest_name }}'
          owner: "{{ ansible_ssh_user }}"
          group: "{{ ansible_ssh_user }}"
          state: link
          with_items:
          - { src_dir: "{{ npm_real_dir }}", src_name: "{{ npm_real_name }}", dest_dir: "{{ nodenpm_link_dir }}", dest_name: "{{ npm_link_name }}" }
          - { src_dir: "{{ gulp_real_dir }}", src_name: "{{ gulp_real_name }}", dest_dir: "{{ gulp_link_dir }}", dest_name: "{{ gulp_link_name }}" }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 15:27









          nwinklernwinkler

          33k16107128




          33k16107128








          • 1





            oh ok. makes sence about an undefined variable when you are not even passing it. Thanks for your answer :)

            – Fábio Caramelo
            Nov 14 '18 at 16:25














          • 1





            oh ok. makes sence about an undefined variable when you are not even passing it. Thanks for your answer :)

            – Fábio Caramelo
            Nov 14 '18 at 16:25








          1




          1





          oh ok. makes sence about an undefined variable when you are not even passing it. Thanks for your answer :)

          – Fábio Caramelo
          Nov 14 '18 at 16:25





          oh ok. makes sence about an undefined variable when you are not even passing it. Thanks for your answer :)

          – Fábio Caramelo
          Nov 14 '18 at 16:25




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303363%2fcreating-symlinks-with-ansible-using-variables%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python