Open
Description
sorry about that, but I am new with ansible and I want to call this playbook in my playbook as a role.
and I want to know how to use this playbook, were to define the hosts, what should I do,
can you please define a how-to, to explain in steps how to run it and where is the values should I change and where to change,
and for the replica how to enable it, and how to make it a single deployment or replica deployment with attribute
I know that it may be a clear thing but sorry for that.
can you please help me with this
I tried the below to call it a role and pass the var from my playbook but it give me the below error
- hosts: all
tasks:
- name: "get facts about ip addresses"
setup:
filter: ansible_default_ipv4
- name: "set mongodb_replication_params variable"
set_fact:
mongodb_replication_params:
- host_name: "{{ hostvars[item]['ansible_default_ipv4']['address'] }}"
host_type: "{{ replica if 'mongodb-replica' in group_names else arbiter }}"
with_items:
- "{{ groups['mongodb-replica'] }}"
- "{{ groups['mongodb-arbiter'] }}"
debug: msg="echo"
roles:
- ansible-role-mongodb
ERROR! conflicting action statements: set_fact, debug
The error appears to be in '/root/newmongo.yaml': line 7, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
filter: ansible_default_ipv4
- name: "set mongodb_replication_params variable"
^ here
I tried to use the below also,
- hosts: all
tasks:
- name: determine which ethernet interface holds the ip we want to use in mongo
set_fact:
eth_interface: "ansible_eth1"
when: stage == "development"
- name: determine which ethernet interface holds the ip we want to use in mongo
set_fact:
eth_interface: "ansible_eth0"
when: stage != "development"
- name: determine who is the master
set_fact:
mongodb_masternode: "{{ groups['mongodb-datastore'][0] }}"
- name: determine the master ip
set_fact:
mongodb_masternode_ip: "{{ hostvars[mongodb_masternode][eth_interface]['ipv4']['address'] }}"
- name: echo mongodb_masternode ip
debug: msg={{ mongodb_masternode_ip }}
- name: determine own ip
set_fact:
own_ip: "{{ ansible_eth1.ipv4.address }}"
when: stage == "development"
- name: determine own ip
set_fact:
own_ip: "{{ ansible_eth0.ipv4.address }}"
when: stage != "development"
- name: echo my ip
debug: msg={{ own_ip }}
- name: test if this machine is not the master
set_fact:
mongodb_master: false
when: mongodb_masternode_ip != own_ip
- name: test if this machine is the master
set_fact:
mongodb_master: true
when: mongodb_masternode_ip == own_ip
- name: Build replication json config
set_fact:
replication: "{{ lookup('template', 'mongodb_replication_params.j2') }}"
# note that we build a _string_ here containing json, not a json object
vars:
hosts: "{{ groups['mongodb-datastore'] + groups['mongodb-arbiter'] }}"
- name: echo replication
debug: msg={{ replication }}
- name: Convert replication json to an ansible variable mongodb_replication_params
set_fact:
mongodb_replication_params: "{{ replication|from_json }}"
- name: echo mongodb_replication_params
debug: msg={{ mongodb_replication_params }}
roles:
- ansible-role-mongodb
it gives me the below error
TASK [determine which ethernet interface holds the ip we want to use in mongo] *******************************************************
fatal: [192.168.1.46]: FAILED! => {"msg": "The conditional check 'stage == \"development\"' failed. The error was: error while evaluating conditional (stage == \"development\"): 'stage' is undefined\n\nThe error appears to be in '/root/mongo.yaml': line 3, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: determine which ethernet interface holds the ip we want to use in mongo\n ^ here\n"}
Metadata
Metadata
Assignees
Labels
No labels