mkouhei / ansible-role-includecsv Goto Github PK
View Code? Open in Web Editor NEWLoad variables from a CSV file, dynamically within a task.
License: GNU General Public License v3.0
Load variables from a CSV file, dynamically within a task.
License: GNU General Public License v3.0
In the repo README.md file there is a link (https://galaxy.ansible.com/detail#/role/6589) Ansible Galaxy Page of this role/module but there is no content there . the page is empty.
The code example there says
- include:csv: src=bar.csv
I expect that should be
- include_csv: src=bar.csv
hi,
thanks for the code. In your example,
- include_csv: src=path/to/fruits.csv
and you call the objects using using the csv name without the extension
with_items: "{{hostvars.localhost.fruits}}"
In above case, the registered value of the csv will become fruits
and is hardcoded
But how to do this, when the filename itself is dynamic? and if I don't know the physical CSV name
for e.g.
- include_csv: src={{my_dynamic_csv}}
How to call the objects from above example? (I don't know the physical name of my_dynamic_csv
)
Hello Kouhei Maeda,
Thanks for module, I wrote below code to execute the SQLPLUS against the remote DB. I have client schema names and connection string in CSV as below format.
"DB_SCHEMA","SYSTEM_USER","SYSTEM_PASSWORD","TNS_NAME","TNS_DESCRIPTION" "ClientSchema1","admin","password","server1","(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))" "ClientSchema_2","admin","password2","server2","(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server2)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))" "ClientSchema_3","admin","password2","server2","(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server2)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
- include_csv: src=/PATH_TO_CSV/client_schema_output.csv delimiter="," shell: source ~/.bash_profile && sqlplus -S '{{ item.SYSTEM_USER }}/{{ item.SYSTEM_PASSWORD }}@{{ item.TNS_DESCRIPTION }}' @"roles/my_role/files/client.sql" {{ item.DB_SCHEMA }} connection: local sudo: no with_items: "{{ client_schema_output }}"
However for some reason it's not picking dynamic CSV, I did see CSV got updated with latest entries but not my task, it's still running against old TNS entries.
changed: [10.202.98.198] => (item={u'DB_SCHEMA': u'ClientSchema_1', u'SYSTEM_PASSWORD': u'password', u'SYSTEM_USER': u'admin', u'TNS_DESCRIPTION': u'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))', u'TNS_NAME': u'server1'}) => { "changed": true, "cmd": "source ~/.bash_profile && sqlplus -S 'admin/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))' @\"roles/MY_Role/files/hotfix_client.sql\" ClientSchema_1",
This is never getting changes even though I updated the CSV with new entries.
Please let me know if I am doing something wrong here.
Thank you
Unable to use module, due to error below:
{"msg": "Error: Module unable to decode valid JSON on stdin. Unable to figure out what parameters were passed", "failed": true}
Ansible 2.7.7
Python 3.6.5
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ansible/module_utils/basic.py", line 707, in _load_params
params = json.loads(buffer.decode('utf-8'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/init.py", line 354, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "action_plugins/include_csv", line 58, in
main()
File "action_plugins/include_csv", line 39, in main
supports_check_mode=True,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ansible/module_utils/basic.py", line 846, in init
self._load_params()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ansible/module_utils/basic.py", line 2146, in _load_params
self.params = _load_params()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ansible/module_utils/basic.py", line 711, in _load_params
sys.exit(1)
SystemExit: 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.