[ansible-project] Re: MongoDB Lookup

2017-12-25 Thread David Resnick
Though actually the plugin does work when using it with the "lookup" syntax.

The tasks in the plugin docs should be replaced with this:

 tasks:

- set_fact:

entry: "{{ lookup('mongodb', mongodb_parameters) }}"

- debug: msg="Mongo has already started with the following PID [{{ 
entry.pid }}]"


- David

On Monday, December 25, 2017 at 11:34:25 AM UTC+2, David Resnick wrote:
>
> Yes, the mongodb lookup plugin is broken in ansible >= 2.4.1.0.
>
> The problem is with this line 
> <https://github.com/ansible/ansible/blob/4d67cdd1f73ced35dc63aa422a996b7496e0a710/lib/ansible/plugins/lookup/mongodb.py#L168>
> :
>
> def run(self, terms, variables, **kwargs):
> ret = []
> for term in terms:
> When trying to run the example from the documentation, terms holds a 
> dictionary with the mongo parameters and not a list.
>
> I will try to open an issue and submit a pull request for fixing this.
>
> - David
>
>
> On Saturday, November 4, 2017 at 6:29:30 PM UTC+2, Marcelo Oliveira wrote:
>>
>> Hello everybody, 
>>
>> I am learning ansible through its official documentation and videos on 
>> youtube, but sadly I can't get it working with its lookup-mongodb module as 
>> described at 
>> http://docs.ansible.com/ansible/latest/playbooks_lookups.html#mongodb-lookup
>> I am using Ubuntu 16.04 based distro (Elementary OS Loki), Python 2.7.12, 
>> ansible 2.4.1.0 (installed from ppa:ansible/ansible) and I have 
>> also python-pymongo version 3.2-1build1 installed.
>>
>> When I try to run the example taught in the official documentation (see 
>> link above), I got the following error:
>>
>>
>> app@store:~/ansible_tutorial$ ansible-playbook playbook.yml -vvv
>> ansible-playbook 2.4.1.0
>>   config file = /home/app/ansible_tutorial/ansible.cfg
>>   configured module search path = [u'/home/app/.ansible/plugins/modules', 
>> u'/usr/share/ansible/plugins/modules']
>>   ansible python module location = 
>> /usr/lib/python2.7/dist-packages/ansible
>>   executable location = /usr/bin/ansible-playbook
>>   python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 
>> 20160609]
>> Using /home/app/ansible_tutorial/ansible.cfg as config file
>> Parsed /home/app/ansible_tutorial/hosts inventory source with ini plugin
>>
>> PLAYBOOK: playbook.yml 
>> **
>> 1 plays in playbook.yml
>>
>> PLAY [localhost] 
>> 
>> META: ran handlers
>>
>> TASK [debug] 
>> 
>> task path: /home/app/ansible_tutorial/playbook.yml:26
>> The full traceback is:
>> Traceback (most recent call last):
>>   File 
>> "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 
>> 88, in run
>> items = self._get_loop_items()
>>   File 
>> "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 
>> 216, in _get_loop_items
>> items = mylookup.run(terms=loop_terms, variables=self._job_vars, 
>> wantlist=True)
>>   File 
>> "/usr/lib/python2.7/dist-packages/ansible/plugins/lookup/mongodb.py", line 
>> 210, in run
>> *connection_string = term.get(u'connection_string', 
>> u"mongodb://localhost")*
>> *AttributeError: 'unicode' object has no attribute 'get'*
>>
>> *fatal: [localhost]: FAILED! => {*
>> *"msg": "Unexpected failure during module execution.", *
>> *"stdout": ""*
>> *}*
>> to retry, use: --limit @/home/app/ansible_tutorial/playbook.retry
>>
>> PLAY RECAP 
>> **
>> localhost  : ok=0changed=0unreachable=0   
>>  failed=1 
>>
>>
>> As far as I can understand, those bold lines are telling me what is going 
>> wrong, the connection to the database.
>> I've searched everywhere I could on internet and watched many ansible 
>> videos on youtube but I couldn't find how I can fix it, it must be 
>

[ansible-project] Re: MongoDB Lookup

2017-12-25 Thread David Resnick
Yes, the mongodb lookup plugin is broken in ansible >= 2.4.1.0.

The problem is with this line 

:

def run(self, terms, variables, **kwargs):
ret = []
for term in terms:
When trying to run the example from the documentation, terms holds a 
dictionary with the mongo parameters and not a list.

I will try to open an issue and submit a pull request for fixing this.

- David


On Saturday, November 4, 2017 at 6:29:30 PM UTC+2, Marcelo Oliveira wrote:
>
> Hello everybody, 
>
> I am learning ansible through its official documentation and videos on 
> youtube, but sadly I can't get it working with its lookup-mongodb module as 
> described at 
> http://docs.ansible.com/ansible/latest/playbooks_lookups.html#mongodb-lookup
> I am using Ubuntu 16.04 based distro (Elementary OS Loki), Python 2.7.12, 
> ansible 2.4.1.0 (installed from ppa:ansible/ansible) and I have 
> also python-pymongo version 3.2-1build1 installed.
>
> When I try to run the example taught in the official documentation (see 
> link above), I got the following error:
>
>
> app@store:~/ansible_tutorial$ ansible-playbook playbook.yml -vvv
> ansible-playbook 2.4.1.0
>   config file = /home/app/ansible_tutorial/ansible.cfg
>   configured module search path = [u'/home/app/.ansible/plugins/modules', 
> u'/usr/share/ansible/plugins/modules']
>   ansible python module location = /usr/lib/python2.7/dist-packages/ansible
>   executable location = /usr/bin/ansible-playbook
>   python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 
> 20160609]
> Using /home/app/ansible_tutorial/ansible.cfg as config file
> Parsed /home/app/ansible_tutorial/hosts inventory source with ini plugin
>
> PLAYBOOK: playbook.yml 
> **
> 1 plays in playbook.yml
>
> PLAY [localhost] 
> 
> META: ran handlers
>
> TASK [debug] 
> 
> task path: /home/app/ansible_tutorial/playbook.yml:26
> The full traceback is:
> Traceback (most recent call last):
>   File 
> "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 
> 88, in run
> items = self._get_loop_items()
>   File 
> "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 
> 216, in _get_loop_items
> items = mylookup.run(terms=loop_terms, variables=self._job_vars, 
> wantlist=True)
>   File 
> "/usr/lib/python2.7/dist-packages/ansible/plugins/lookup/mongodb.py", line 
> 210, in run
> *connection_string = term.get(u'connection_string', 
> u"mongodb://localhost")*
> *AttributeError: 'unicode' object has no attribute 'get'*
>
> *fatal: [localhost]: FAILED! => {*
> *"msg": "Unexpected failure during module execution.", *
> *"stdout": ""*
> *}*
> to retry, use: --limit @/home/app/ansible_tutorial/playbook.retry
>
> PLAY RECAP 
> **
> localhost  : ok=0changed=0unreachable=0   
>  failed=1 
>
>
> As far as I can understand, those bold lines are telling me what is going 
> wrong, the connection to the database.
> I've searched everywhere I could on internet and watched many ansible 
> videos on youtube but I couldn't find how I can fix it, it must be 
> something very simple.
>
> From the MongoDB side:
> I installed it in the same machine, it is running, and it has the local 
> database and startup_log collection, as you may find below:
>
> app@store:~/ansible_tutorial$ mongo
> MongoDB shell version: 3.2.17
> connecting to: test
> Server has startup warnings: 
> 2017-11-04T09:39:25.859-0200 I CONTROL  [initandlisten] 
> 2017-11-04T09:39:25.859-0200 I CONTROL  [initandlisten] ** WARNING: 
> /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
> 2017-11-04T09:39:25.859-0200 I CONTROL  [initandlisten] **We 
> suggest setting it to 'never'
> 2017-11-04T09:39:25.859-0200 I CONTROL  [initandlisten] 
> > show dbs
> *local  0.000GB*
> > use local
> switched to db local
> > show collections
> *startup_log*
> > db.startup_log.find()
> { "_id" : "store-1509763862598", "hostname" : "store", "startTime" : 
> ISODate("2017-11-04T02:51:02Z"), "startTimeLocal" : "Sat Nov  4 
> 00:51:02.598", "cmdLine" : { "config" : "/etc/mongod.conf", "net" : { 
> "bindIp" : "127.0.0.1", "port" : 27017 }, "storage" : { "dbPath" : 
> "/var/lib/mongodb", "journal" : { "enabled" : true } }, "systemLog" : { 
> "destination" : "file", "logAppend" : true, "

[ansible-project] become:yes for local connection: when and how often is sudo called?

2016-08-31 Thread David Resnick
Hi,

I'm trying to understand when ansible uses sudo in a scenario where a 
playbook with become:yes is running with a local connection.

I have a playbook where I need to change the default execution PATH in 
sudoers for a following step to succeed. In order to run the playbook 
remotely, I need the tasks to run under "become:yes"

Something like this:

- hosts: all
  become: yes
  tasks:
- name: Add npm executable to sudo secure_path
  lineinfile:
dest: /etc/sudoers
regexp: '^(Defaultssecure_path = 
/sbin:/bin:/usr/sbin:/usr/bin)$'
line: '\1:/usr/local/lib/npm/bin'
backrefs: yes
state: present
- name: Add service to run PM2
  shell: /usr/local/lib/npm/bin/pm2 startup systemd --user nodejs --hp 
/home/nodejs
  args:
creates: /etc/systemd/system/pm2.service

Running each of the above tasks in separate sessions sets things up 
properly. But when I run this locally in the same play, the change to the 
sudoers file has no effect on the "pm2 startup" task.

When does ansible call sudo? Just at the start of the block? Is there any 
way to force ansible to leave a sudo session and to start a new one?

Thanks,
David

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f6f5deff-2fd0-47f7-8c7a-19d309d5131f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: group_vars behavior changed in 2.1?

2016-08-23 Thread David Resnick
OK, I see that this behavior change is being shown as a bug fix in 2.1.2:

* Fixed a bug where a group_vars or host_vars directory in the current 
> working directory would be used (and would take precedence) over those in 
> the inventory and/or playbook directory.


It would be nice if the group_vars directory in the current working 
directory was used as before.

- David

On Wednesday, August 24, 2016 at 7:37:11 AM UTC+3, David Resnick wrote:
>
> Is it possible that previously Ansible looked for group_vars in the 
> current directory (i.e. a sub-directory of the current one)?
>
> Because of multiple inventory files, I put inventory files in a 
> sub-directory; in this structure:
>
> project/ 
> ├── group_vars/ 
> │   └── all.yml
> ├── playbooks/ 
> │   └── deploy.yml
> └── inventory/
> ├── staging
> └── production
>
> I run like this
>
> project$ ansible-playbook -i inventory/staging playbooks/deploy.yml
>
> In 2.1.0 variables defined in group_vars were picked up; in 2.1.1 they are 
> not. 
>
> Is there any way to configure a "group_vars path" to allow using this 
> structure in 2.1.1? From your previous answer, I'm guessing there isn't.
>
> - David
>
> On Tuesday, August 23, 2016 at 4:34:45 PM UTC+3, Brian Coca wrote:
>>
>> Ansible has no concept of 'project', group/host_vars MUST be adjacent to 
>> either inventory or the play and should be picked up automatically if they 
>> match an group or host from inventory.
>>
>> The vars_files will look for relative paths in a 'vars/' directory 
>> adjacent to play or relative to the play, vars_files does not look into 
>> group/host_vars.
>>
>>
>> --
>> Brian Coca
>>
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/853f1582-3c66-4467-b56c-1f62677cb18c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: group_vars behavior changed in 2.1?

2016-08-23 Thread David Resnick
Is it possible that previously Ansible looked for group_vars in the current 
directory (i.e. a sub-directory of the current one)?

Because of multiple inventory files, I put inventory files in a 
sub-directory; in this structure:

project/ 
├── group_vars/ 
│   └── all.yml
├── playbooks/ 
│   └── deploy.yml
└── inventory/
├── staging
└── production

I run like this

project$ ansible-playbook -i inventory/staging playbooks/deploy.yml

In 2.1.0 variables defined in group_vars were picked up; in 2.1.1 they are 
not. 

Is there any way to configure a "group_vars path" to allow using this 
structure in 2.1.1? From your previous answer, I'm guessing there isn't.

- David

On Tuesday, August 23, 2016 at 4:34:45 PM UTC+3, Brian Coca wrote:
>
> Ansible has no concept of 'project', group/host_vars MUST be adjacent to 
> either inventory or the play and should be picked up automatically if they 
> match an group or host from inventory.
>
> The vars_files will look for relative paths in a 'vars/' directory 
> adjacent to play or relative to the play, vars_files does not look into 
> group/host_vars.
>
>
> --
> Brian Coca
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ef7fd2a8-9e8d-4a21-9a1f-c68f1cfa75aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: group_vars behavior changed in 2.1?

2016-08-22 Thread David Resnick
I just posted about this too, it looks like a bug to me.

- David

On Thursday, August 18, 2016 at 7:41:27 PM UTC+3, Vincent Jørgensen wrote:
>
> Hi all, I have an ansible project with a groups_vars directory, with a 
> subdirectory called all beneath it, like so:
> /project/group_vars/all/ami.yml
> /project/group_vars/all/dns.yml
> /project/group_vars/all/key.yml
>
> Previously, I didn't have to specify in my playbook the path to each 
> variable file (amis dns and keys change often enough that it's handy to 
> keep them separate). But since moving to 2.1.1.0, ansible can't find the 
> files under all, so I've had to resort to this:
> - hosts:  localhost
>   ...
>   vars_files:
> - "{{ base_dir }}/group_vars/all/dns.yml"
> - "{{ base_dir }}/group_vars/all/ami.yml"
> - "{{ base_dir }}/group_vars/all/key.yml"
>   tasks:
>   - ...
>
>
> Did this feature go away?  It isn't the end of the world, but I liked that 
> feature, that all could be directory or a file. Thanks. \V
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ce1020e4-332e-4016-ab2c-ce411f2f2948%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] localhost in multiple groups (e.g. all) as well as "ungrouped"

2016-08-22 Thread David Resnick
I've found a regression in Ansible 2.1.1.0 where group_vars are not being 
applied correctly to a host that is shown as part of those groups.

My playbook is for performing AWS operations.

My inventory file looks something like this:

[control_host]
localhost connection=local
[nonprod]
[eu-nonprod]
[eu-west-1]
[demo]
[eu-west-1:children]
control_host
[demo:children]
control_host
[nonprod:children]
eu-nonprod
demo
[eu-nonprod:children]
eu-west-1

When I run this with Ansible 2.1.1 my groups_vars are not picked up -- 
including values set in group_vars/all.yml. With 2.1.0 group_vars are set 
as expected.

I'm not sure this is connected, but I've noticed that localhost is shown as 
belonging to all expected groups when running with 2.1.0 -- and with 
Ansible 2.1.1 localhost is shown to belong to the "ungrouped" group as well.

TASK [debug] 
***
ok: [localhost] => {
"groups": {
"all": [
"localhost"
],
"control_host": [
"localhost"
],
"demo": [
"localhost"
],
"eu-nonprod": [
"localhost"
],
"eu-west-1": [
"localhost"
],
"nonprod": [
"localhost"
],
"ungrouped": [
"localhost"
]
}
}

Am I missing something here? Should I open an issue about this?

Thanks,
David

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/637adf5a-cb5d-4f62-9bbc-dc19c2b43670%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Templating JSON to send with uri

2016-02-17 Thread David Resnick
"{{ lookup('template','add-datasource.json') | from_json }}" worked.

Thanks for responding so quickly; I didn't notice the replies because 
notifications weren't enabled.

- David

On Wednesday, February 10, 2016 at 5:52:34 PM UTC+2, Brian Coca wrote:
>
> The JSON from the template (w/o filters) will be 'typed' by Ansible into a 
> Python data structure, but if it has to_json it will be kept as string 
> bypassing the typing. The from_json will convert it to a Python data 
> structure before Ansible attempts to type it.
>
>
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3ab620a8-76d6-4462-988c-a312da1ff4a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Templating JSON to send with uri

2016-02-10 Thread David Resnick
I'm trying to POST some JSON that I have in a file. 

This is the code I have:

task.yml:

---

- name: grafana | add graphite as data source
  uri:
url: http://{{ ansible_host }}:3000/api/datasources
method: POST
user: "{{ grafana_admin_user }}"
password: "{{ grafana_admin_password }}"
body: "{{ lookup('template','add-datasource.json') }}"
force_basic_auth: yes
status_code: 200
body_format: json
  delegate_to: localhost
  become: no

add-datasource.json:

{  "name":"grafite",  "type":"graphite",  "access":"proxy", 
 "url":"http://{{ ansible_host }}/",  "password":"",  "user":"", 
 "database":"",  "basicAuth":true,  "basicAuthUser":"", 
 "basicAuthPassword":"",  "withCredentials":false,  "isDefault":true, 
 "jsonData":null}

When I run that I get this error:

fatal: [mats -> localhost]: FAILED! => {"changed": false, "content": 
"[{\"classification\":\"DeserializationError\",\"message\":\"json: cannot 
unmarshal string into Go value of type 
models.AddDataSourceCommand\"},{\"fieldNames\":[\"Name\"],\"classification\":\"RequiredError\",\"message\":\"Required\"},{\"fieldNames\":[\"Type\"],\"classification\":\"RequiredError\",\"message\":\"Required\"},{\"fieldNames\":[\"Access\"],\"classification\":\"RequiredError\",\"message\":\"Required\"}]",
 
"content_length": "371", "content_type": "application/json; charset=utf-8", 
"date": "Wed, 10 Feb 2016 06:56:29 GMT", "failed": true, "invocation": 
{"module_args": {"backup": null, "body": "{  \"name\":\"grafite\", 
 \"type\":\"graphite\",  \"access\":\"proxy\", 
 \"url\":\"http://10.225.39.185/\";,  \"password\":\"\",  \"user\":\"\", 
 \"database\":\"\",  \"basicAuth\":true,  \"basicAuthUser\":\"\", 
 \"basicAuthPassword\":\"\",  \"withCredentials\":false, 
 \"isDefault\":true,  \"jsonData\":null}\n", "body_format": "json", 
"content": null, "creates": null, "delimiter": null, "dest": null, 
"directory_mode": null, "follow": false, "follow_redirects": "safe", 
"force": null, "force_basic_auth": true, "group": null, "method": "POST", 
"mode": null, "owner": null, "password": "W6v^tfVgv", "regexp": null, 
"remote_src": null, "removes": null, "return_content": false, "selevel": 
null, "serole": null, "setype": null, "seuser": null, "src": null, 
"status_code": ["200"], "timeout": 30, "url": 
"http://10.225.39.185:3000/api/datasources";, "user": "admin", 
"validate_certs": true}, "module_name": "uri"}, "json": [{"classification": 
"DeserializationError", "message": "json: cannot unmarshal string into Go 
value of type models.AddDataSourceCommand"}, {"classification": 
"RequiredError", "fieldNames": ["Name"], "message": "Required"}, 
{"classification": "RequiredError", "fieldNames": ["Type"], "message": 
"Required"}, {"classification": "RequiredError", "fieldNames": ["Access"], 
"message": "Required"}], "msg": "Status code was not [200]", "redirected": 
false, "status": 400}

When I use the json file inline as the body, then it succeeds:

task.yml:

---

- name: grafana | add graphite as data source
  uri:
url: http://{{ ansible_host }}:3000/api/datasources
method: POST
user: "{{ grafana_admin_user }}"
password: "{{ grafana_admin_password }}"
body: { "name":"grafite",  "type":"graphite",  "access":"proxy", 
 "url":"http://{{ ansible_host }}/",  "password":"",  "user":"", 
 "database":"",  "basicAuth":true,  "basicAuthUser":"", 
 "basicAuthPassword":"",  "withCredentials":false,  "isDefault":true, 
 "jsonData":null }
force_basic_auth: yes
status_code: 200
body_format: json
  delegate_to: localhost
  become: no

The problem might be related to issue 
https://github.com/ansible/ansible/issues/7005

Though I am using the same format as the uri example 
 for creating a JIRA issue.

Ansible version 2.0.0.2.

What am I missing?

- David

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/08e6a989-246c-4932-9868-b03577c4ed92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.