I am having the following playbook in ansible where "{{env}}" is a dynamic variable: could be sit,nft,prod,etc - based on user selection. The action in the play should be executed only if the selected environment is nft.
- hosts: "{{ host }}"
remote_user: "{{ user }}"
vars:
home_dir: "/home/{{ user }}"
env: "{{ env }}"
tasks:
- name: backup file
copy:
src: "/home/dtcd/gabi/FF_environmentConfig.ini"
dest: "/home/dtcd/gabi/FF_environmentConfig.ini_orig"
remote_src: yes
- name: change params nft
lineinfile:
path: "/home/dtcd/gabi/FF_environmentConfig.ini"
regexp: '{{item.From}}'
line: '{{item.To}}'
state: present
with_items:
- { From: 'FF_AMQProcessingMessageTimeoutInMilliseconds=5000', To: 'FF_AMQProcessingMessageTimeoutInMilliseconds=10000' }
- { From: 'FF_solutionDetectionServiceProcess_FF_ALL_FF_customFeedChannel_ConcurrentThreads=1', To: 'FF_solutionDetectionServiceProcess_FF_ALL_FF_customFeedChannel_ConcurrentThreads=10' }
when: env == nft
Now, when I am running the playbook, it errors out with the message:
fatal: [servera.com]: FAILED! => { "msg": "The conditional check 'env == nft' failed. The error was: error while evaluating conditional (env == nft): 'nft' is undefined\n\nThe error appears to be in '/ansible-playbook/1-sed.yml': line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: change params nft\n ^ here\n" }
I have tried using when: "{{env}}" == "nft", using set_facts... but in the end I am still facing the error above.
Using set_facts I was able to overcome the error, however the actions were skipped, despite env=nft.
What am I missing here?
Thanks!
when: env == "nft"
?